Browse Source

Encode event search queries in URL query string

master
buttercat1791 7 months ago
parent
commit
6d91bb7fc0
  1. 55
      src/lib/components/EventSearch.svelte
  2. 2
      src/lib/models/search_type.d.ts
  3. 9
      src/routes/events/+page.svelte

55
src/lib/components/EventSearch.svelte

@ -143,6 +143,54 @@
return; 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 // Handle different search types
const searchType = getSearchType(query); const searchType = getSearchType(query);
if (searchType) { if (searchType) {
@ -151,9 +199,7 @@
} }
// AI-NOTE: 2025-01-24 - If no specific search type is detected, treat as event ID search // AI-NOTE: 2025-01-24 - If no specific search type is detected, treat as event ID search
if (clearInput) { // URL navigation is now handled in the URL update logic above
navigateToSearch(query, "id");
}
await handleEventSearch(query); await handleEventSearch(query);
} }
@ -210,7 +256,7 @@
if (type === "d") { if (type === "d") {
console.log("EventSearch: Processing d-tag search:", term); console.log("EventSearch: Processing d-tag search:", term);
navigateToSearch(term, "d"); // URL navigation is now handled in handleSearchEvent
updateSearchState(false, false, null, null); updateSearchState(false, false, null, null);
return; return;
} }
@ -222,6 +268,7 @@
if (type === "event") { if (type === "event") {
console.log("EventSearch: Processing event ID search:", term); console.log("EventSearch: Processing event ID search:", term);
// URL navigation is now handled in handleSearchEvent
await handleEventSearch(term); await handleEventSearch(term);
return; return;
} }

2
src/lib/models/search_type.d.ts vendored

@ -1 +1 @@
export type SearchType = "id" | "d" | "t" | "n"; export type SearchType = "id" | "d" | "t" | "n" | "q";

9
src/routes/events/+page.svelte

@ -179,6 +179,7 @@
const dParam = url.get("d"); const dParam = url.get("d");
const tParam = url.get("t"); const tParam = url.get("t");
const nParam = url.get("n"); const nParam = url.get("n");
const qParam = url.get("q");
if (idParam) { if (idParam) {
searchValue = idParam; searchValue = idParam;
@ -192,6 +193,9 @@
} else if (nParam) { } else if (nParam) {
searchValue = decodeURIComponent(nParam); searchValue = decodeURIComponent(nParam);
searchType = "n"; searchType = "n";
} else if (qParam) {
searchValue = decodeURIComponent(qParam);
searchType = "q";
} else { } else {
searchValue = null; searchValue = null;
searchType = null; searchType = null;
@ -200,11 +204,12 @@
// Handle side panel visibility based on search type // Handle side panel visibility based on search type
$effect(() => { $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 ( if (
searchType === "d" || searchType === "d" ||
searchType === "t" || searchType === "t" ||
searchType === "n" searchType === "n" ||
searchType === "q"
) { ) {
showSidePanel = false; showSidePanel = false;
event = null; event = null;

Loading…
Cancel
Save