|
71 | 71 | } |
72 | 72 | } |
73 | 73 |
|
| 74 | + function changeViewMode(mode: ViewMode) { |
| 75 | + viewMode = mode; |
| 76 | + const params = new SvelteURLSearchParams(page.url.search); |
| 77 | + if (mode === 'search') { |
| 78 | + params.delete('v'); |
| 79 | + } else { |
| 80 | + params.set('v', mode); |
| 81 | + } |
| 82 | + const href = resolve(`/?${params.toString()}`); |
| 83 | + goto(href, { replaceState: true, keepFocus: true, noScroll: true }); |
| 84 | + } |
| 85 | +
|
74 | 86 | function goToPage(p: number) { |
75 | 87 | if (p < 1 || p > totalPages || loading) return; |
76 | 88 | const q = query.trim(); |
|
89 | 101 | } |
90 | 102 |
|
91 | 103 | lastSubmittedQuery = q; |
| 104 | + showLowScore = false; |
92 | 105 | const href = resolve(q ? `/?q=${encodeURIComponent(q)}` : '/'); |
93 | 106 |
|
94 | 107 | await goto(href, { replaceState: true, keepFocus: true, noScroll: true }); |
|
97 | 110 | $effect(() => { |
98 | 111 | const q = page.url.searchParams.get('q') ?? ''; |
99 | 112 | const p = Math.max(1, Number(page.url.searchParams.get('p') ?? '1')); |
| 113 | + const v = page.url.searchParams.get('v') as ViewMode | null; |
| 114 | +
|
| 115 | + if (v === 'search' || v === 'cards') { |
| 116 | + viewMode = v; |
| 117 | + } |
100 | 118 |
|
101 | 119 | if (q !== untrack(() => lastSearchedQuery) || p !== untrack(() => currentPage)) { |
102 | 120 | query = q; |
|
212 | 230 | <Button |
213 | 231 | variant={viewMode === 'search' ? 'default' : 'ghost'} |
214 | 232 | size="sm" |
215 | | - onclick={() => (viewMode = 'search')} |
| 233 | + onclick={() => changeViewMode('search')} |
216 | 234 | > |
217 | 235 | <Search class="h-4 w-4" /> |
218 | 236 | </Button> |
219 | 237 | <Button |
220 | 238 | variant={viewMode === 'cards' ? 'default' : 'ghost'} |
221 | 239 | size="sm" |
222 | | - onclick={() => (viewMode = 'cards')} |
| 240 | + onclick={() => changeViewMode('cards')} |
223 | 241 | > |
224 | 242 | <LayoutGrid class="h-4 w-4" /> |
225 | 243 | </Button> |
|
242 | 260 | {@const trueHiddenCount = Math.max(0, totalResults - pageOffset - validResults.length)} |
243 | 261 | {@const showHiddenResultsNotice = hiddenCount > 0 && validResults.length > 0} |
244 | 262 | {#if showHiddenResultsNotice && !loading} |
245 | | - <p class="mt-4 text-center text-sm text-muted-foreground"> |
| 263 | + <p class="mt-6 text-center text-sm text-muted-foreground"> |
246 | 264 | {trueHiddenCount} result{trueHiddenCount !== 1 ? 's' : ''} hidden... |
247 | 265 | <button |
248 | 266 | class="cursor-pointer underline hover:text-foreground" |
|
0 commit comments