diff --git a/src/renderer/components/chat/ChatList.tsx b/src/renderer/components/chat/ChatList.tsx index ce0d329de4..fee8291841 100644 --- a/src/renderer/components/chat/ChatList.tsx +++ b/src/renderer/components/chat/ChatList.tsx @@ -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 } } @@ -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 } }