Feed: fix date range eager-load — use primary let-vars, cover feed pages
Previous attempt used dateFrom (a derived $: variable) as the trigger which Svelte 5 doesn't reliably track as a dependency of a side-effect $: block. Replace with the primary let-variables (customFrom, customTo, datePre) that Svelte does track statically. Also extend eager-loading to cover the global combined feed (feedNextPage) so date/search filtering works on multi-user instances too, not just per-user profile pages (pendingShards).
This commit is contained in:
@@ -134,8 +134,12 @@
|
||||
|
||||
// When a search query or any date filter is active, eagerly load all
|
||||
// remaining shards so results aren't limited to the initially-loaded year.
|
||||
// Use only primary let-variables here — Svelte 5 doesn't reliably track
|
||||
// derived $: variables as dependencies of side-effect $: blocks.
|
||||
let loadingAllShards = false;
|
||||
$: if ((query.trim() || dateFrom) && pendingShards.length > 0 && !loadingAllShards) {
|
||||
let loadingAllFeedPages = false;
|
||||
|
||||
$: if ((query.trim() || customFrom || customTo || datePre !== 'all') && pendingShards.length > 0 && !loadingAllShards) {
|
||||
loadingAllShards = true;
|
||||
(async () => {
|
||||
while (pendingShards.length > 0) {
|
||||
@@ -154,6 +158,25 @@
|
||||
})();
|
||||
}
|
||||
|
||||
$: if ((query.trim() || customFrom || customTo || datePre !== 'all') && feedNextPage > 0 && !loadingAllFeedPages) {
|
||||
loadingAllFeedPages = true;
|
||||
(async () => {
|
||||
while (feedNextPage > 0) {
|
||||
const page = feedNextPage;
|
||||
feedNextPage = page < feedTotalPages ? page + 1 : 0;
|
||||
try {
|
||||
const fresh = await loadCombinedFeedPage(base, page);
|
||||
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 */ }
|
||||
}
|
||||
loadingAllFeedPages = 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