Commit 62e5045790

62e50457908191aeb972e7af7bbb67831272ee97

parent: 36e0e5306e

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-09-06 12:27 UTC

Cap to 50 results, with a Show more button to keep loading

Layout: unified · split

web/src/components/things/SearchResults.svelte +40 −3
@@ -18,9 +18,14 @@
18 { key: 'category', label: 'Category' }, 18 { key: 'category', label: 'Category' },
19 ]; 19 ];
20 20
21 const PAGE_SIZE = 50;
22
21 let results: SearchItem[] = $state([]); 23 let results: SearchItem[] = $state([]);
22 let loading = $state(true); 24 let loading = $state(true);
23 let sort: Sort = $state('relevance'); 25 let sort: Sort = $state('relevance');
26 let shown = $state(PAGE_SIZE);
27
28 const visible = $derived(results.slice(0, shown));
24 29
25 onMount(async () => { 30 onMount(async () => {
26 const wanted = new URLSearchParams(location.search).get('sort'); 31 const wanted = new URLSearchParams(location.search).get('sort');
@@ -45,7 +50,7 @@
45 // Group into category > section, keeping the relevance order within each 50 // Group into category > section, keeping the relevance order within each
46 const grouped = $derived.by(() => { 51 const grouped = $derived.by(() => {
47 const categories: Record<string, Record<string, SearchItem[]>> = {}; 52 const categories: Record<string, Record<string, SearchItem[]>> = {};
48 for (const item of results) { 53 for (const item of visible) {
49 const sections = (categories[item.category] ??= {}); 54 const sections = (categories[item.category] ??= {});
50 (sections[item.sectionName || ''] ??= []).push(item); 55 (sections[item.sectionName || ''] ??= []).push(item);
51 } 56 }
@@ -73,6 +78,8 @@
73 <p> 78 <p>
74 {#if loading} 79 {#if loading}
75 Searching for "{searchTerm}"... 80 Searching for "{searchTerm}"...
81 {:else if visible.length < results.length}
82 Showing {visible.length} of {results.length} results for "{searchTerm}"
76 {:else} 83 {:else}
77 {results.length} 84 {results.length}
78 {results.length === 1 ? 'result' : 'results'} for "{searchTerm}" 85 {results.length === 1 ? 'result' : 'results'} for "{searchTerm}"
@@ -113,7 +120,7 @@
113 </section> 120 </section>
114{:else if view === 'relevance'} 121{:else if view === 'relevance'}
115 <section class="service-grid"> 122 <section class="service-grid">
116 {#each results as item (item.path)} 123 {#each visible as item (item.path)}
117 {#if item.service} 124 {#if item.service}
118 <ServiceCard 125 <ServiceCard
119 service={item.service} 126 service={item.service}
@@ -156,6 +163,14 @@
156 </section> 163 </section>
157{/if} 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<style lang="scss"> 174<style lang="scss">
160 .results-head { 175 .results-head {
161 display: flex; 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 .view-all { 217 .view-all {
182 color: var(--accent-3-text); 218 color: var(--accent-3-text);
183 text-decoration: none; 219 text-decoration: none;
@@ -232,7 +268,8 @@
232 268
233 .by-category, 269 .by-category,
234 .service-grid, 270 .service-grid,
235 .nothing-found { 271 .nothing-found,
272 .load-more {
236 max-width: var(--width-container); 273 max-width: var(--width-container);
237 width: calc(100% - 2rem); 274 width: calc(100% - 2rem);
238 margin: 0 auto var(--space-lg) auto; 275 margin: 0 auto var(--space-lg) auto;