From 1126819b73b67ed6ba3785889ee12301fe7a8301 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 9 Jun 2026 16:04:38 +0100 Subject: [PATCH] refac --- .../src/lib/components/Sidebar.svelte | 4 ++- .../src/lib/components/chat/ChatPanel.svelte | 31 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cptr/frontend/src/lib/components/Sidebar.svelte b/cptr/frontend/src/lib/components/Sidebar.svelte index b353b80..3d38117 100644 --- a/cptr/frontend/src/lib/components/Sidebar.svelte +++ b/cptr/frontend/src/lib/components/Sidebar.svelte @@ -308,7 +308,8 @@ - + + {#if $chatEnabled}
Automations
+ {/if}
diff --git a/cptr/frontend/src/lib/components/chat/ChatPanel.svelte b/cptr/frontend/src/lib/components/chat/ChatPanel.svelte index a927a1a..f221d08 100644 --- a/cptr/frontend/src/lib/components/chat/ChatPanel.svelte +++ b/cptr/frontend/src/lib/components/chat/ChatPanel.svelte @@ -294,6 +294,8 @@ // ── Socket listener ───────────────────────────────────────── + let landingRefreshTimer: ReturnType | null = null; + function handleSocketEvent(data: { chat_id: string; message_id: string; @@ -305,15 +307,25 @@ }) { // On the landing page, update the chat list in place from socket events if (isLanding) { - if (data.done) { - previousChats = previousChats.map((c) => - c.id === data.chat_id ? { ...c, is_active: false } : c - ); - } - if (data.title) { - previousChats = previousChats.map((c) => - c.id === data.chat_id ? { ...c, title: data.title! } : c - ); + const knownChat = previousChats.some((c) => c.id === data.chat_id); + if (!knownChat) { + // New chat created elsewhere — debounce-reload the list + if (landingRefreshTimer) clearTimeout(landingRefreshTimer); + landingRefreshTimer = setTimeout(() => { + landingRefreshTimer = null; + loadPreviousChats(chatPage); + }, 300); + } else { + if (data.done) { + previousChats = previousChats.map((c) => + c.id === data.chat_id ? { ...c, is_active: false } : c + ); + } + if (data.title) { + previousChats = previousChats.map((c) => + c.id === data.chat_id ? { ...c, title: data.title! } : c + ); + } } } @@ -419,6 +431,7 @@ socket.off('events:chat', handleSocketEvent); socket.off('connect', handleReconnect); } + if (landingRefreshTimer) clearTimeout(landingRefreshTimer); // Don't clear streamingChatTabs here -- the global listener in // chat.ts handles cleanup when the "done" event arrives, so the // spinner persists even when the chat tab is not active.