From bef3da2a567e3804e12355d9c3d5c09439dbe2ea Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 17 Jul 2025 23:42:55 +0200 Subject: Humble beginnings Redirect to login if not logged in, on login session cookie is set and projects or reviews are listed. --- client/src/routes/(app)/+page.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 client/src/routes/(app)/+page.ts (limited to 'client/src/routes/(app)/+page.ts') diff --git a/client/src/routes/(app)/+page.ts b/client/src/routes/(app)/+page.ts new file mode 100644 index 0000000..b6b923e --- /dev/null +++ b/client/src/routes/(app)/+page.ts @@ -0,0 +1,38 @@ +import { client } from '$lib/fetch-client'; +import { get_config } from '$lib/config'; +import type { PageLoad } from './$types'; + +function maybeInt(input: string | null, fallback: number): number { + if (input === null) return fallback; + try { + return parseInt(input); + } catch { + return fallback; + } +} + +export const load: PageLoad = async ({ fetch, url }) => { + const config = await get_config(); + if (config.active_project === undefined) { + const projects = await client.GET('/projects', { + params: { query: { offset: maybeInt(url.searchParams.get('projects_offset'), 0) } }, + fetch + }); + return { + projects: projects.data!!, + reviews: undefined + }; + } else { + const reviews = await client.GET('/project/{projectid}/reviews', { + params: { + path: { projectid: config.active_project }, + query: { offset: maybeInt(url.searchParams.get('reviews_offset'), 0) } + }, + fetch + }); + return { + projects: undefined, + reviews: reviews.data + }; + } +}; -- cgit v1.2.3-70-g09d2