Chore: Remove selectedChat from store (#1087)

* Chore: Remove selected chat from store
This commit is contained in:
Pranav Raj S
2020-07-23 23:33:17 +05:30
committed by GitHub
parent e72f29a26e
commit c7d962b20f
7 changed files with 76 additions and 84 deletions

View File

@@ -2,9 +2,9 @@ import authAPI from '../../../api/auth';
export const getSelectedChatConversation = ({
allConversations,
selectedChat,
selectedChatId,
}) =>
allConversations.filter(conversation => conversation.id === selectedChat.id);
allConversations.filter(conversation => conversation.id === selectedChatId);
// getters
const getters = {
@@ -12,7 +12,12 @@ const getters = {
allConversations.sort(
(a, b) => b.messages.last()?.created_at - a.messages.last()?.created_at
),
getSelectedChat: ({ selectedChat }) => selectedChat,
getSelectedChat: ({ selectedChatId, allConversations }) => {
const selectedChat = allConversations.find(
conversation => conversation.id === selectedChatId
);
return selectedChat || {};
},
getMineChats(_state) {
const currentUserID = authAPI.getCurrentUser().id;
return _state.allConversations.filter(chat =>
@@ -53,7 +58,7 @@ const getters = {
getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter,
getSelectedInbox: ({ currentInbox }) => currentInbox,
getNextChatConversation: _state => {
const { selectedChat } = _state;
const [selectedChat] = getSelectedChatConversation(_state);
const conversations = getters.getAllStatusChats(_state);
if (conversations.length <= 1) {
return null;