feat(documents): add fetchDensity helper and /documents/+page.ts (#385)

The density data is fetched only on tablet/desktop (sm:+ breakpoint) and
when ?view=calendar is not set — mobile users and the future calendar view
(#386) skip the request entirely. Lives in +page.ts (client-side) so the
matchMedia gate can run in the browser; +page.server.ts continues to handle
the document search.

Non-ok responses and network failures degrade to an empty bucket list
rather than throwing, so the document list keeps rendering.

5 unit tests cover the gating + graceful degradation paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-07 22:06:57 +02:00
parent 5fdcc95c3d
commit ad82f2e1e2
3 changed files with 103 additions and 2 deletions

View File

@@ -0,0 +1,9 @@
import { browser } from '$app/environment';
import { fetchDensity } from '$lib/document/timeline';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ url, fetch }) => {
const view = url.searchParams.get('view');
const isDesktop = browser && window.matchMedia('(min-width: 640px)').matches;
return await fetchDensity(fetch, view, isDesktop);
};