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 @@
1818 { key: 'category', label: 'Category' },
1919 ];
2020
21 const PAGE_SIZE = 50;
22
2123 let results: SearchItem[] = $state([]);
2224 let loading = $state(true);
2325 let sort: Sort = $state('relevance');
26 let shown = $state(PAGE_SIZE);
27
28 const visible = $derived(results.slice(0, shown));
2429
2530 onMount(async () => {
2631 const wanted = new URLSearchParams(location.search).get('sort');
@@ -45,7 +50,7 @@
4550 // Group into category > section, keeping the relevance order within each
4651 const grouped = $derived.by(() => {
4752 const categories: Record<string, Record<string, SearchItem[]>> = {};
48 for (const item of results) {
53 for (const item of visible) {
4954 const sections = (categories[item.category] ??= {});
5055 (sections[item.sectionName || ''] ??= []).push(item);
5156 }
@@ -73,6 +78,8 @@
7378 <p>
7479 {#if loading}
7580 Searching for "{searchTerm}"...
81 {:else if visible.length < results.length}
82 Showing {visible.length} of {results.length} results for "{searchTerm}"
7683 {:else}
7784 {results.length}
7885 {results.length === 1 ? 'result' : 'results'} for "{searchTerm}"
@@ -113,7 +120,7 @@
113120 </section>
114121{:else if view === 'relevance'}
115122 <section class="service-grid">
116 {#each results as item (item.path)}
123 {#each visible as item (item.path)}
117124 {#if item.service}
118125 <ServiceCard
119126 service={item.service}
@@ -156,6 +163,14 @@
156163 </section>
157164{/if}
158165
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
159174<style lang="scss">
160175 .results-head {
161176 display: flex;
@@ -178,6 +193,27 @@
178193 }
179194 }
180195
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
181217 .view-all {
182218 color: var(--accent-3-text);
183219 text-decoration: none;
@@ -232,7 +268,8 @@
232268
233269 .by-category,
234270 .service-grid,
235 .nothing-found {
271 .nothing-found,
272 .load-more {
236273 max-width: var(--width-container);
237274 width: calc(100% - 2rem);
238275 margin: 0 auto var(--space-lg) auto;