Skip to content

Commit

Permalink
added await to ensure updated queryData
Browse files Browse the repository at this point in the history
  • Loading branch information
Aad1tya27 committed Jan 12, 2025
1 parent 6e25c29 commit 44fc7d5
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/screens/UserPortal/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,25 @@ export default function chat(): JSX.Element {
}, [selectedContact]);

React.useEffect(() => {
let isMounted = true;
if (filterType === 'all') {
chatsListRefetch().then(() => {
if (isMounted && chatsListData?.chatsByUserId) {
async function getChats(): Promise<void> {
if (filterType === 'all') {
await chatsListRefetch();
if (chatsListData && chatsListData.chatsByUserId) {
setChats(chatsListData.chatsByUserId);
}
});
} else if (filterType === 'unread') {
unreadChatListRefetch().then(() => {
if (isMounted && unreadChatListData?.getUnreadChatsByUserId) {
} else if (filterType === 'unread') {
await unreadChatListRefetch();
if (unreadChatListData && unreadChatListData.getUnreadChatsByUserId) {
setChats(unreadChatListData.getUnreadChatsByUserId);
}
});
} else if (filterType === 'group') {
groupChatListRefetch().then(() => {
if (isMounted && groupChatListData?.getGroupChatsByUserId) {
} else if (filterType === 'group') {
await groupChatListRefetch();
if (groupChatListData && groupChatListData.getGroupChatsByUserId) {
setChats(groupChatListData.getGroupChatsByUserId);
}
});
}
}
return () => {
isMounted = false;
};
getChats();
}, [filterType]);

React.useEffect(() => {
Expand Down

0 comments on commit 44fc7d5

Please sign in to comment.