From 29f415d786657dab6124e8d66a8577344df47ce1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 26 Aug 2020 23:20:16 -0500 Subject: [PATCH] Chats: sort most recently updated chats to the top --- app/soapbox/features/chats/components/chat_list.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/soapbox/features/chats/components/chat_list.js b/app/soapbox/features/chats/components/chat_list.js index ca5349b20..0928c3040 100644 --- a/app/soapbox/features/chats/components/chat_list.js +++ b/app/soapbox/features/chats/components/chat_list.js @@ -10,7 +10,18 @@ import { makeGetChat } from 'soapbox/selectors'; const mapStateToProps = state => { const getChat = makeGetChat(); return { - chats: state.get('chats').map(chat => getChat(state, chat.toJS())), + chats: state.get('chats').map(chat => + getChat(state, chat.toJS()) + ).sort((valueA, valueB) => { + // Sort most recently updated chats at the top + const a = new Date(valueA.get('updated_at')); + const b = new Date(valueB.get('updated_at')); + + if (a === b) return 0; + if (a > b) return -1; + if (a < b) return 1; + return 0; + }), }; };