From 04beacde6154a751139705d65f24330bf1124796 Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Tue, 13 May 2025 15:35:59 +0200 Subject: [PATCH] ui: reset kai thread on site change --- frontend/app/components/Kai/KaiChat.tsx | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/frontend/app/components/Kai/KaiChat.tsx b/frontend/app/components/Kai/KaiChat.tsx index aad1c7612..1d855aa00 100644 --- a/frontend/app/components/Kai/KaiChat.tsx +++ b/frontend/app/components/Kai/KaiChat.tsx @@ -24,20 +24,19 @@ function KaiChat() { const [initialMsg, setInitialMsg] = React.useState(null); const { showModal, hideModal } = useModal(); const location = useLocation(); - const params = new URLSearchParams(location.search); - const threadIdFromUrl = params.get('threadId'); React.useEffect(() => { - // Reset chat state and clear URL params when project changes - setSection('intro'); - setThreadId(null); history.replace({ search: '' }); - }, [activeSiteId]); + setThreadId(null); + setSection('intro'); + setInitialMsg(null); + setTitle(null); + }, [activeSiteId, history]); const openChats = () => { showModal( { setTitle(title); setThreadId(threadId); @@ -49,11 +48,19 @@ function KaiChat() { }; React.useEffect(() => { + if ( + activeSiteId && + parseInt(activeSiteId, 10) !== parseInt(location.pathname.split('/')[1], 10) + ) { + return; + } + const params = new URLSearchParams(location.search); + const threadIdFromUrl = params.get('threadId'); if (threadIdFromUrl) { setThreadId(threadIdFromUrl); setSection('chat'); } - }, [threadIdFromUrl]); + }, []); React.useEffect(() => { if (threadId) { @@ -138,14 +145,14 @@ function ChatsModal({ isPending, refetch, } = useQuery({ - queryKey: ['kai', 'chats'], + queryKey: ['kai', 'chats', projectId], queryFn: () => kaiService.getKaiChats(projectId), staleTime: 1000 * 60, }); const onDelete = async (id: string) => { try { - await kaiService.deleteKaiChat(projectId, userId, id); + await kaiService.deleteKaiChat(projectId, id); } catch (e) { toast.error("Something wen't wrong. Please try again later."); }