From a3a2429727677b69ce461902bf1f7ed1a461366f Mon Sep 17 00:00:00 2001 From: gdbroman <99gustaf@gmail.com> Date: Wed, 28 Jun 2023 17:41:22 +0200 Subject: [PATCH] Fix "loading new messages" state --- app/src/renderer/apps/Courier/app.tsx | 2 +- .../apps/Courier/views/Inbox/Inbox.tsx | 5 ++-- .../StandaloneChat/StandaloneChatBody.tsx | 2 +- app/src/renderer/stores/chat.store.ts | 26 ++++++++++++------- app/src/renderer/stores/ship.store.ts | 6 +++-- .../SystemBar/components/ShipBar/index.tsx | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/src/renderer/apps/Courier/app.tsx b/app/src/renderer/apps/Courier/app.tsx index ebedfecd77..aa82926066 100644 --- a/app/src/renderer/apps/Courier/app.tsx +++ b/app/src/renderer/apps/Courier/app.tsx @@ -33,7 +33,7 @@ export const CourierAppPresenter = () => { clearInnerNavigation(); }, [chatStore.subroute]); - if (chatStore.loader.isFirstLoad) { + if (chatStore.inboxInitLoader.isFirstLoad) { return ( { const { sortedChatList, sortedStandaloneChatList, - loader, + inboxLoader, + inboxMetadataLoader, setChat, setSubroute, isChatPinned, @@ -35,7 +36,7 @@ export const InboxPresenter = ({ isStandaloneChat = false }: Props) => { accountIdentity={loggedInAccount?.serverId} spacePath={currentSpace?.path} isStandaloneChat={isStandaloneChat} - isLoading={loader.isLoading} + isLoading={inboxLoader.isLoading || inboxMetadataLoader.isLoading} isChatPinned={isChatPinned} onClickInbox={(path) => { setChat(path); diff --git a/app/src/renderer/apps/StandaloneChat/StandaloneChatBody.tsx b/app/src/renderer/apps/StandaloneChat/StandaloneChatBody.tsx index f4facece15..0556930a21 100644 --- a/app/src/renderer/apps/StandaloneChat/StandaloneChatBody.tsx +++ b/app/src/renderer/apps/StandaloneChat/StandaloneChatBody.tsx @@ -53,7 +53,7 @@ export const StandaloneChatBodyPresenter = () => { } }, [chatStore.subroute, chatStore.selectedChat, chatStore.inbox]); - if (chatStore.loader.isFirstLoad) { + if (chatStore.inboxInitLoader.isFirstLoad) { return ( ({ isChatPinned(path: string) { @@ -153,8 +155,9 @@ export const ChatStore = types })) .actions((self) => ({ init: flow(function* () { + self.inboxInitLoader.set('loading'); + try { - self.loader.set('loading'); const pinnedChats = yield ChatIPC.fetchPinnedChats(); const muted = yield ChatIPC.fetchMuted(); self.inbox = yield ChatIPC.getChatList(); @@ -167,17 +170,19 @@ export const ChatStore = types console.error(error); } - self.loader.set('loaded'); + self.inboxInitLoader.set('loaded'); return self.inbox; }), fetchInboxMetadata: flow(function* () { + self.inboxMetadataLoader.set('loading'); const { muted, pinned } = yield ChatIPC.fetchPathMetadata(); self.pinnedChats = pinned; self.mutedChats = muted; + self.inboxMetadataLoader.set('loaded'); }), loadChatList: flow(function* () { - self.loader.set('loading'); + self.inboxLoader.set('loading'); try { self.inbox = yield ChatIPC.getChatList(); @@ -185,7 +190,7 @@ export const ChatStore = types console.error(error); } - self.loader.set('loaded'); + self.inboxLoader.set('loaded'); }), findChatDM: flow(function* (peer: string, our: string) { // find the DM, if exists, where it's only ourselves and the peer @@ -209,15 +214,17 @@ export const ChatStore = types } self.subroute = subroute; }), - setChat(path: string) { + setChat: flow(function* (path: string) { + self.chatLoader.set('loading'); self.selectedChat = tryReference(() => self.inbox.find((chat) => chat.path === path) ); - ChatIPC.refreshMessagesOnPath(path, window.ship); + yield ChatIPC.refreshMessagesOnPath(path, window.ship); if (self.subroute === 'inbox') { self.subroute = 'chat'; } - }, + self.chatLoader.set('loaded'); + }), togglePinned: flow(function* (path: string, pinned: boolean) { try { if (pinned) { @@ -314,10 +321,9 @@ export const ChatStore = types self.isOpen = false; }, _onInit(payload: any) { - if (self.loader.isFirstLoad) { + if (self.inboxInitLoader.isFirstLoad) { self.inbox = payload; localStorage.setItem(`${window.ship}-firstLoad`, 'true'); - self.loader.set('loaded'); } }, })); diff --git a/app/src/renderer/stores/ship.store.ts b/app/src/renderer/stores/ship.store.ts index 9dc2a6b4b0..e94413a344 100644 --- a/app/src/renderer/stores/ship.store.ts +++ b/app/src/renderer/stores/ship.store.ts @@ -34,7 +34,7 @@ export const ShipStore = types .actions((self) => ({ init(session: RealmSessionCredentials) { if (!localStorage.getItem(`${session.serverId}-firstLoad`)) { - self.chatStore.loader.set('first-load'); + self.chatStore.inboxInitLoader.set('first-load'); } self.credentials = CredentialsModel.create(session); self.friends.init(); @@ -109,8 +109,10 @@ export const shipStore = ShipStore.create({ subroute: 'inbox', isOpen: false, pinnedChats: [], - loader: { state: 'loading' }, inboxLoader: { state: 'initial' }, + inboxInitLoader: { state: 'loading' }, + inboxMetadataLoader: { state: 'loading' }, + chatLoader: { state: 'initial' }, }, spacesStore: { spaces: {}, diff --git a/app/src/renderer/system/desktop/components/SystemBar/components/ShipBar/index.tsx b/app/src/renderer/system/desktop/components/SystemBar/components/ShipBar/index.tsx index b0ff7ebdea..74e2f80e8c 100644 --- a/app/src/renderer/system/desktop/components/SystemBar/components/ShipBar/index.tsx +++ b/app/src/renderer/system/desktop/components/SystemBar/components/ShipBar/index.tsx @@ -227,7 +227,7 @@ export const ShipBarPresenter = () => { }} > - {chatStore.loader.isFirstLoad ? ( + {chatStore.inboxInitLoader.isFirstLoad ? (