From cfb091856508b3f224a529f49f662c9aaf40aca4 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 11 Jun 2026 10:34:15 +0100 Subject: [PATCH] refac --- .../src/lib/components/SearchModal.svelte | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cptr/frontend/src/lib/components/SearchModal.svelte b/cptr/frontend/src/lib/components/SearchModal.svelte index 75b41dc..c565fc6 100644 --- a/cptr/frontend/src/lib/components/SearchModal.svelte +++ b/cptr/frontend/src/lib/components/SearchModal.svelte @@ -30,11 +30,19 @@ let debounceTimer: ReturnType | null = null; let resultsEl: HTMLDivElement | undefined = $state(); + // Determine active workspace from the URL, not the store. + // When on /automations or other non-workspace pages, $currentWorkspace + // retains the last workspace but we should search across all. + const urlWorkspacePath = $derived($page.url.searchParams.get('workspace')); + const effectiveWorkspace = $derived( + urlWorkspacePath ? $currentWorkspace : null + ); + // Show recents when no query, search results when query exists const showingRecents = $derived(!query.trim()); const filteredRecents = $derived( - $currentWorkspace - ? recentChats.filter((c) => c.workspace === $currentWorkspace!.path) + effectiveWorkspace + ? recentChats.filter((c) => c.workspace === effectiveWorkspace!.path) : recentChats ); const displayedChats = $derived(showingRecents ? filteredRecents : chatResults); @@ -71,11 +79,11 @@ debounceTimer = setTimeout(() => doSearch(query), 250); }); - // When a workspace is active, scope to files from that workspace only - const isWorkspaceScoped = $derived(!!$currentWorkspace); + // When a workspace is explicitly active via URL, scope to files from that workspace only + const isWorkspaceScoped = $derived(!!effectiveWorkspace); async function doSearch(q: string) { - const activeWs = $currentWorkspace; + const activeWs = effectiveWorkspace; if (activeWs) { // Workspace active: search chats + files scoped to this workspace