Skip to content

Commit

Permalink
chore: show loader when loading previous messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-deriv committed Aug 3, 2023
1 parent 26817ec commit a1c61c2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/p2p/src/stores/sendbird-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default class SendbirdStore extends BaseStore {
await this.initialiseOrderChannel();
}
} catch (error) {
this.setChatError();
// handle sendbird error
}
}

Expand All @@ -178,21 +178,22 @@ export default class SendbirdStore extends BaseStore {
this.setActiveChatChannel(group_channel);
}
} catch (error) {
this.setChatError();
// handle sendbird error
} finally {
this.setIsChatLoading(false);
}
}

async initialiseOrderMessages() {
this.setHasChatError(false);
this.setIsChatLoading(true);
try {
const chat_messages = await this.getPreviousMessages();
if (chat_messages && chat_messages.length > 0) {
this.setChannelMessages(chat_messages.map(msg => convertFromChannelMessage(msg)));
}
} catch (error) {
this.setHasChatError(true);
// handle sendbird error
} finally {
this.setIsChatLoading(false);
}
Expand Down Expand Up @@ -277,7 +278,7 @@ export default class SendbirdStore extends BaseStore {
}
}
} catch (error) {
this.setHasChatError(true);
// handle sendbird error
}
}

Expand All @@ -299,6 +300,7 @@ export default class SendbirdStore extends BaseStore {
if (!this.messages_ref?.current) return;

if (this.messages_ref.current.scrollTop === 0) {
this.setIsChatLoading(true);
const oldest_message_timestamp = this.chat_messages.reduce(
(prev_created_at, chat_message) =>
chat_message.created_at < prev_created_at ? chat_message.created_at : prev_created_at,
Expand All @@ -313,9 +315,10 @@ export default class SendbirdStore extends BaseStore {

this.replaceChannelMessage(0, 0, previous_messages[0]);
}
this.setIsChatLoading(false);
})
.catch(() => {
this.setHasChatError(true);
// handle sendbird error
});
} else {
(async () => {
Expand Down

0 comments on commit a1c61c2

Please sign in to comment.