Skip to content

Commit

Permalink
Fix "loading new messages" state
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbroman committed Jun 28, 2023
1 parent 966c4c4 commit a3a2429
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/src/renderer/apps/Courier/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const CourierAppPresenter = () => {
clearInnerNavigation();
}, [chatStore.subroute]);

if (chatStore.loader.isFirstLoad) {
if (chatStore.inboxInitLoader.isFirstLoad) {
return (
<Flex
position="absolute"
Expand Down
5 changes: 3 additions & 2 deletions app/src/renderer/apps/Courier/views/Inbox/Inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const InboxPresenter = ({ isStandaloneChat = false }: Props) => {
const {
sortedChatList,
sortedStandaloneChatList,
loader,
inboxLoader,
inboxMetadataLoader,
setChat,
setSubroute,
isChatPinned,
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const StandaloneChatBodyPresenter = () => {
}
}, [chatStore.subroute, chatStore.selectedChat, chatStore.inbox]);

if (chatStore.loader.isFirstLoad) {
if (chatStore.inboxInitLoader.isFirstLoad) {
return (
<Flex
position="absolute"
Expand Down
26 changes: 16 additions & 10 deletions app/src/renderer/stores/chat.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export const ChatStore = types
inbox: types.array(Chat),
selectedChat: types.maybe(types.reference(Chat)),
isOpen: types.boolean,
loader: LoaderModel,
inboxLoader: LoaderModel,
inboxInitLoader: LoaderModel,
inboxMetadataLoader: LoaderModel,
chatLoader: LoaderModel,
})
.views((self) => ({
isChatPinned(path: string) {
Expand Down Expand Up @@ -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();
Expand All @@ -167,25 +170,27 @@ 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();
} catch (error) {
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
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
}
},
}));
Expand Down
6 changes: 4 additions & 2 deletions app/src/renderer/stores/ship.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export const ShipBarPresenter = () => {
}}
>
<Scroller>
{chatStore.loader.isFirstLoad ? (
{chatStore.inboxInitLoader.isFirstLoad ? (
<Flex
isSkeleton
flexDirection="column"
Expand Down

0 comments on commit a3a2429

Please sign in to comment.