Search: auto-load all year shards when a query is entered so full history is searched
This commit is contained in:
@@ -128,6 +128,28 @@
|
||||
|
||||
$: if (sport || datePre || query) shown = PAGE_SIZE; // reset pagination on filter change
|
||||
|
||||
// When a search query is active, eagerly load all remaining shards so the
|
||||
// full history is searched (not just the initially-loaded recent year).
|
||||
let loadingAllShards = false;
|
||||
$: if (query.trim() && pendingShards.length > 0 && !loadingAllShards) {
|
||||
loadingAllShards = true;
|
||||
(async () => {
|
||||
while (pendingShards.length > 0) {
|
||||
const url = pendingShards[0];
|
||||
pendingShards = pendingShards.slice(1);
|
||||
try {
|
||||
const fresh = await loadShardActivities(url);
|
||||
const existing = new Map(all.map(a => [a.id, a]));
|
||||
for (const a of fresh) if (!existing.has(a.id)) existing.set(a.id, a);
|
||||
all = [...existing.values()].sort((a, b) =>
|
||||
(b.started_at ?? '').localeCompare(a.started_at ?? ''),
|
||||
);
|
||||
} catch { /* ignore — partial results still useful */ }
|
||||
}
|
||||
loadingAllShards = false;
|
||||
})();
|
||||
}
|
||||
|
||||
$: if (mounted) {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (sport === 'all') params.delete('sport'); else params.set('sport', sport);
|
||||
|
||||
Reference in New Issue
Block a user