diff --git a/src/lib/components/EventSearch.svelte b/src/lib/components/EventSearch.svelte index e4faf0e..f4c4310 100644 --- a/src/lib/components/EventSearch.svelte +++ b/src/lib/components/EventSearch.svelte @@ -143,6 +143,54 @@ return; } + // Update URL with search query for all search types + if (clearInput) { + const searchType = getSearchType(query); + if (searchType) { + const { type, term } = searchType; + const encoded = encodeURIComponent(term); + if (type === "d") { + goto(`?d=${encoded}`, { + replaceState: false, + keepFocus: true, + noScroll: true, + }); + } else if (type === "t") { + goto(`?t=${encoded}`, { + replaceState: false, + keepFocus: true, + noScroll: true, + }); + } else if (type === "n") { + goto(`?n=${encoded}`, { + replaceState: false, + keepFocus: true, + noScroll: true, + }); + } else if (type === "nip05") { + goto(`?q=${encodeURIComponent(query)}`, { + replaceState: false, + keepFocus: true, + noScroll: true, + }); + } else if (type === "event") { + goto(`?id=${encoded}`, { + replaceState: false, + keepFocus: true, + noScroll: true, + }); + } + } else { + // No specific search type detected, treat as general search + const encoded = encodeURIComponent(query); + goto(`?q=${encoded}`, { + replaceState: false, + keepFocus: true, + noScroll: true, + }); + } + } + // Handle different search types const searchType = getSearchType(query); if (searchType) { @@ -151,9 +199,7 @@ } // AI-NOTE: 2025-01-24 - If no specific search type is detected, treat as event ID search - if (clearInput) { - navigateToSearch(query, "id"); - } + // URL navigation is now handled in the URL update logic above await handleEventSearch(query); } @@ -210,7 +256,7 @@ if (type === "d") { console.log("EventSearch: Processing d-tag search:", term); - navigateToSearch(term, "d"); + // URL navigation is now handled in handleSearchEvent updateSearchState(false, false, null, null); return; } @@ -222,6 +268,7 @@ if (type === "event") { console.log("EventSearch: Processing event ID search:", term); + // URL navigation is now handled in handleSearchEvent await handleEventSearch(term); return; } diff --git a/src/lib/models/search_type.d.ts b/src/lib/models/search_type.d.ts index db33e7f..b6d448f 100644 --- a/src/lib/models/search_type.d.ts +++ b/src/lib/models/search_type.d.ts @@ -1 +1 @@ -export type SearchType = "id" | "d" | "t" | "n"; +export type SearchType = "id" | "d" | "t" | "n" | "q"; diff --git a/src/routes/events/+page.svelte b/src/routes/events/+page.svelte index d024149..2d25714 100644 --- a/src/routes/events/+page.svelte +++ b/src/routes/events/+page.svelte @@ -179,6 +179,7 @@ const dParam = url.get("d"); const tParam = url.get("t"); const nParam = url.get("n"); + const qParam = url.get("q"); if (idParam) { searchValue = idParam; @@ -192,6 +193,9 @@ } else if (nParam) { searchValue = decodeURIComponent(nParam); searchType = "n"; + } else if (qParam) { + searchValue = decodeURIComponent(qParam); + searchType = "q"; } else { searchValue = null; searchType = null; @@ -200,11 +204,12 @@ // Handle side panel visibility based on search type $effect(() => { - // Close side panel for searches that return multiple results (d-tag, t-tag, name searches) + // Close side panel for searches that return multiple results (d-tag, t-tag, name searches, general searches) if ( searchType === "d" || searchType === "t" || - searchType === "n" + searchType === "n" || + searchType === "q" ) { showSidePanel = false; event = null;