Commit 62e5045790
Unsigned
Layout: unified · split
web/src/components/things/SearchResults.svelte +40 −3
| @@ -18,9 +18,14 @@ | ||
| 18 | 18 | { key: 'category', label: 'Category' }, |
| 19 | 19 | ]; |
| 20 | 20 | |
| 21 | const PAGE_SIZE = 50; | |
| 22 | ||
| 21 | 23 | let results: SearchItem[] = $state([]); |
| 22 | 24 | let loading = $state(true); |
| 23 | 25 | let sort: Sort = $state('relevance'); |
| 26 | let shown = $state(PAGE_SIZE); | |
| 27 | ||
| 28 | const visible = $derived(results.slice(0, shown)); | |
| 24 | 29 | |
| 25 | 30 | onMount(async () => { |
| 26 | 31 | const wanted = new URLSearchParams(location.search).get('sort'); |
| @@ -45,7 +50,7 @@ | ||
| 45 | 50 | // Group into category > section, keeping the relevance order within each |
| 46 | 51 | const grouped = $derived.by(() => { |
| 47 | 52 | const categories: Record<string, Record<string, SearchItem[]>> = {}; |
| 48 | for (const item of results) { | |
| 53 | for (const item of visible) { | |
| 49 | 54 | const sections = (categories[item.category] ??= {}); |
| 50 | 55 | (sections[item.sectionName || ''] ??= []).push(item); |
| 51 | 56 | } |
| @@ -73,6 +78,8 @@ | ||
| 73 | 78 | <p> |
| 74 | 79 | {#if loading} |
| 75 | 80 | Searching for "{searchTerm}"... |
| 81 | {:else if visible.length < results.length} | |
| 82 | Showing {visible.length} of {results.length} results for "{searchTerm}" | |
| 76 | 83 | {:else} |
| 77 | 84 | {results.length} |
| 78 | 85 | {results.length === 1 ? 'result' : 'results'} for "{searchTerm}" |
| @@ -113,7 +120,7 @@ | ||
| 113 | 120 | </section> |
| 114 | 121 | {:else if view === 'relevance'} |
| 115 | 122 | <section class="service-grid"> |
| 116 | {#each results as item (item.path)} | |
| 123 | {#each visible as item (item.path)} | |
| 117 | 124 | {#if item.service} |
| 118 | 125 | <ServiceCard |
| 119 | 126 | service={item.service} |
| @@ -156,6 +163,14 @@ | ||
| 156 | 163 | </section> |
| 157 | 164 | {/if} |
| 158 | 165 | |
| 166 | {#if shown < results.length} | |
| 167 | <section class="load-more"> | |
| 168 | <button type="button" onclick={() => (shown += PAGE_SIZE)}> | |
| 169 | Show {Math.min(PAGE_SIZE, results.length - shown)} more | |
| 170 | </button> | |
| 171 | </section> | |
| 172 | {/if} | |
| 173 | ||
| 159 | 174 | <style lang="scss"> |
| 160 | 175 | .results-head { |
| 161 | 176 | display: flex; |
| @@ -178,6 +193,27 @@ | ||
| 178 | 193 | } |
| 179 | 194 | } |
| 180 | 195 | |
| 196 | .load-more { | |
| 197 | display: flex; | |
| 198 | justify-content: center; | |
| 199 | ||
| 200 | button { | |
| 201 | cursor: pointer; | |
| 202 | font-family: inherit; | |
| 203 | font-size: var(--text-md); | |
| 204 | padding: var(--space-sm) var(--space-lg); | |
| 205 | color: var(--accent-3-text); | |
| 206 | background: var(--surface); | |
| 207 | border: var(--border-heavy); | |
| 208 | border-radius: var(--curve-sm); | |
| 209 | transition: var(--transition-normal); | |
| 210 | ||
| 211 | &:hover { | |
| 212 | box-shadow: var(--shadow-md); | |
| 213 | } | |
| 214 | } | |
| 215 | } | |
| 216 | ||
| 181 | 217 | .view-all { |
| 182 | 218 | color: var(--accent-3-text); |
| 183 | 219 | text-decoration: none; |
| @@ -232,7 +268,8 @@ | ||
| 232 | 268 | |
| 233 | 269 | .by-category, |
| 234 | 270 | .service-grid, |
| 235 | .nothing-found { | |
| 271 | .nothing-found, | |
| 272 | .load-more { | |
| 236 | 273 | max-width: var(--width-container); |
| 237 | 274 | width: calc(100% - 2rem); |
| 238 | 275 | margin: 0 auto var(--space-lg) auto; |