Files
familienarchiv/frontend/src/routes/stammbaum/+page.server.ts
Marcel bb2a89da58 feat(stammbaum): land a fresh visit at readable z=3, keep fit-to-screen at z=1 (#692)
A fresh visit (no URL state) now opens at INITIAL_VIEW (z=3) so node tiles and
generation labels are legible on arrival; the fit-to-screen control still zooms
out to the whole tree (DEFAULT_VIEW, z=1). Shared links with ?z still win.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-29 18:00:17 +02:00

31 lines
1.1 KiB
TypeScript

import { error, redirect } from '@sveltejs/kit';
import { createApiClient, extractErrorCode } from '$lib/shared/api.server';
import { getErrorMessage } from '$lib/shared/errors';
import { parsePanZoomParams, INITIAL_VIEW } from '$lib/person/genealogy/panZoom';
export async function load({ fetch, url }) {
const api = createApiClient(fetch);
const result = await api.GET('/api/network');
if (result.response.status === 401) throw redirect(302, '/login');
if (!result.response.ok) {
throw error(result.response.status, getErrorMessage(extractErrorCode(result.error)));
}
// A fresh visit (no shared pan/zoom state) lands at the readable INITIAL_VIEW
// (z=3). When a link carries a zoom param we honour it, sanitising server-side
// so a crafted link (?z=Infinity, ?cx=NaN) degrades to a safe view before
// reaching layout geometry (Nora #692).
const initialView = url.searchParams.has('z')
? parsePanZoomParams({
cx: url.searchParams.get('cx'),
cy: url.searchParams.get('cy'),
z: url.searchParams.get('z')
})
: INITIAL_VIEW;
const network = result.data!;
return { nodes: network.nodes ?? [], edges: network.edges ?? [], initialView };
}