summaryrefslogtreecommitdiff
path: root/client/src/routes/(app)/+page.ts
diff options
context:
space:
mode:
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
+ };
+ }
+};