Redirect / til første workspace-side automatisk

Både workspace-switch og direkte navigering til rot-URL
lander nå på første konfigurerte side i stedet for tom oversikt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
vegard 2026-03-15 02:36:32 +01:00
parent a93ffc6de5
commit 7c5b809802

View file

@ -1,8 +1,15 @@
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import type { PageConfig } from '$lib/types/pages';
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
const WORKSPACE_COOKIE = 'sidelinja_workspace'; const WORKSPACE_COOKIE = 'sidelinja_workspace';
function getFirstPageSlug(workspace: { settings?: unknown } | null): string | null {
const settings = workspace?.settings as Record<string, unknown> | undefined;
const pages = (settings?.pages as PageConfig[]) ?? [];
return pages[0]?.slug ?? null;
}
export const load: PageServerLoad = async ({ url, cookies, locals }) => { export const load: PageServerLoad = async ({ url, cookies, locals }) => {
const switchTo = url.searchParams.get('switch_workspace'); const switchTo = url.searchParams.get('switch_workspace');
@ -16,7 +23,13 @@ export const load: PageServerLoad = async ({ url, cookies, locals }) => {
sameSite: 'lax', sameSite: 'lax',
maxAge: 60 * 60 * 24 * 365 maxAge: 60 * 60 * 24 * 365
}); });
const firstPage = getFirstPageSlug(ws);
if (firstPage) redirect(303, `/p/${firstPage}`);
} }
redirect(303, '/'); redirect(303, '/');
} }
// Vanlig landing på / — redirect til første side
const firstPage = getFirstPageSlug(locals.workspace);
if (firstPage) redirect(303, `/p/${firstPage}`);
}; };