Skip to content

Commit

Permalink
replace workaround to force refresh initial data with a better one
Browse files Browse the repository at this point in the history
only use it when view changed, now it does not hide errors in the upper ten entries anymore
  • Loading branch information
Simon-Laux committed Jun 20, 2023
1 parent 5ee83ff commit dd1c075
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/renderer/components/chat/ChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,6 @@ export function useLogicVirtualChatList(chatListIds: number[]) {
}
}, [accountId])

// effects

useEffect(() => {
// force refresh of initial data
loadChats(0, Math.min(chatListIds.length, 10))
}, [chatListIds]) // eslint-disable-line react-hooks/exhaustive-deps

return { isChatLoaded, loadChats, chatCache }
}

Expand All @@ -617,6 +610,19 @@ function useLogicChatPart(
[showArchivedChats, queryStr, setListFlags]
)

// for example user switched to search or to archived chats
// so force refresh of inital data
const shouldReload = useRef(false)
useEffect(() => {
shouldReload.current = true
}, [showArchivedChats, queryStr]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (shouldReload.current) {
shouldReload.current = false
loadChats(0, Math.min(chatListIds.length, 20))
}
}, [chatListIds]) // eslint-disable-line react-hooks/exhaustive-deps

return { chatListIds, isChatLoaded, loadChats, chatCache }
}

Expand Down

0 comments on commit dd1c075

Please sign in to comment.