summaryrefslogtreecommitdiff
path: root/client/src/routes/(app)/+page.ts
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-07-17 23:42:55 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-07-17 23:44:11 +0200
commitbef3da2a567e3804e12355d9c3d5c09439dbe2ea (patch)
treeab7974c941bd31994da46150234976b33c2f61b5 /client/src/routes/(app)/+page.ts
parent145be2b3c92e254904d4040850e3c1e9b6a66f32 (diff)
Humble beginnings
Redirect to login if not logged in, on login session cookie is set and projects or reviews are listed.
Diffstat (limited to 'client/src/routes/(app)/+page.ts')
-rw-r--r--client/src/routes/(app)/+page.ts38
1 files changed, 38 insertions, 0 deletions
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
+ };
+ }
+};