Skip to content

Commit bee4053

Browse files
committed
feat: save view + apply score color
1 parent c316263 commit bee4053

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

frontend/src/lib/components/CardsView.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import Code from '@lucide/svelte/icons/code';
77
import ExternalLink from '@lucide/svelte/icons/external-link';
88
import Star from '@lucide/svelte/icons/star';
9-
import { imageUrl, title, truncate } from '$lib/search';
9+
import { imageUrl, scoreClass, title, truncate } from '$lib/search';
1010
import type { SearchResult } from '$lib/types';
11-
import { formatHours, formatApproved, formatFloat } from '$lib/utils';
11+
import { formatHours, formatApproved, formatFloat, cn } from '$lib/utils';
1212
import { resolve } from '$app/paths';
1313
1414
let { results }: { results: SearchResult[] } = $props();
@@ -65,7 +65,7 @@
6565
·
6666
{/if}
6767
{#if r.score !== null && r.score <= 1}
68-
<span class="text-xs text-muted-foreground" title="Search score"
68+
<span class={cn('text-xs', scoreClass(r.score))} title="Search score"
6969
>Score {formatFloat(r.score * 100, 1)}%</span
7070
>
7171
{/if}

frontend/src/routes/+page.svelte

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@
7171
}
7272
}
7373
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+
7486
function goToPage(p: number) {
7587
if (p < 1 || p > totalPages || loading) return;
7688
const q = query.trim();
@@ -89,6 +101,7 @@
89101
}
90102
91103
lastSubmittedQuery = q;
104+
showLowScore = false;
92105
const href = resolve(q ? `/?q=${encodeURIComponent(q)}` : '/');
93106
94107
await goto(href, { replaceState: true, keepFocus: true, noScroll: true });
@@ -97,6 +110,11 @@
97110
$effect(() => {
98111
const q = page.url.searchParams.get('q') ?? '';
99112
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+
}
100118
101119
if (q !== untrack(() => lastSearchedQuery) || p !== untrack(() => currentPage)) {
102120
query = q;
@@ -212,14 +230,14 @@
212230
<Button
213231
variant={viewMode === 'search' ? 'default' : 'ghost'}
214232
size="sm"
215-
onclick={() => (viewMode = 'search')}
233+
onclick={() => changeViewMode('search')}
216234
>
217235
<Search class="h-4 w-4" />
218236
</Button>
219237
<Button
220238
variant={viewMode === 'cards' ? 'default' : 'ghost'}
221239
size="sm"
222-
onclick={() => (viewMode = 'cards')}
240+
onclick={() => changeViewMode('cards')}
223241
>
224242
<LayoutGrid class="h-4 w-4" />
225243
</Button>
@@ -242,7 +260,7 @@
242260
{@const trueHiddenCount = Math.max(0, totalResults - pageOffset - validResults.length)}
243261
{@const showHiddenResultsNotice = hiddenCount > 0 && validResults.length > 0}
244262
{#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">
246264
{trueHiddenCount} result{trueHiddenCount !== 1 ? 's' : ''} hidden...
247265
<button
248266
class="cursor-pointer underline hover:text-foreground"

0 commit comments

Comments
 (0)