diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-07-17 23:42:55 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-07-17 23:44:11 +0200 |
| commit | bef3da2a567e3804e12355d9c3d5c09439dbe2ea (patch) | |
| tree | ab7974c941bd31994da46150234976b33c2f61b5 /client/src/routes | |
| parent | 145be2b3c92e254904d4040850e3c1e9b6a66f32 (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')
| -rw-r--r-- | client/src/routes/(app)/+error.svelte | 5 | ||||
| -rw-r--r-- | client/src/routes/(app)/+layout.svelte | 12 | ||||
| -rw-r--r-- | client/src/routes/(app)/+layout.ts | 6 | ||||
| -rw-r--r-- | client/src/routes/(app)/+page.svelte | 25 | ||||
| -rw-r--r-- | client/src/routes/(app)/+page.ts | 38 | ||||
| -rw-r--r-- | client/src/routes/+page.svelte | 2 | ||||
| -rw-r--r-- | client/src/routes/login/+page.server.ts | 36 | ||||
| -rw-r--r-- | client/src/routes/login/+page.svelte | 22 | ||||
| -rw-r--r-- | client/src/routes/login/+page.ts | 7 |
9 files changed, 151 insertions, 2 deletions
diff --git a/client/src/routes/(app)/+error.svelte b/client/src/routes/(app)/+error.svelte new file mode 100644 index 0000000..63f3d66 --- /dev/null +++ b/client/src/routes/(app)/+error.svelte @@ -0,0 +1,5 @@ +<script lang="ts"> + import { page } from '$app/state'; +</script> + +<h1>{page.status} {page.error?.message}</h1> diff --git a/client/src/routes/(app)/+layout.svelte b/client/src/routes/(app)/+layout.svelte new file mode 100644 index 0000000..47dc736 --- /dev/null +++ b/client/src/routes/(app)/+layout.svelte @@ -0,0 +1,12 @@ +<script lang="ts"> + let { children } = $props(); +</script> + +<h1>eyeballs</h1> + +<nav> + <a href="/">Dashboard</a> + <a href="/settings">Settings</a> +</nav> + +{@render children()} diff --git a/client/src/routes/(app)/+layout.ts b/client/src/routes/(app)/+layout.ts new file mode 100644 index 0000000..08366b0 --- /dev/null +++ b/client/src/routes/(app)/+layout.ts @@ -0,0 +1,6 @@ +import type { LayoutLoad } from './$types'; + +export const load: LayoutLoad = () => { + // TODO: Decrypt sessioncookie if set, if not set, redirect to /login + return {}; +}; diff --git a/client/src/routes/(app)/+page.svelte b/client/src/routes/(app)/+page.svelte new file mode 100644 index 0000000..945945e --- /dev/null +++ b/client/src/routes/(app)/+page.svelte @@ -0,0 +1,25 @@ +<script lang="ts"> + import type { PageProps } from './$types'; + import ListPrevNext from '$lib/ListPrevNext.svelte'; + let { data }: PageProps = $props(); +</script> + +<h1>Reviews</h1> + +{#if data.reviews === undefined} + Select active project + + <ul> + {#each data.projects!!.projects as { id, title } (id)} + <li>{title}</li> + {/each} + </ul> + <ListPrevNext list={data.projects} query_offset="project_offset" /> +{:else} + <ul> + {#each data.reviews.reviews as { id, title } (id)} + <li>{title}</li> + {/each} + </ul> + <ListPrevNext list={data.reviews} /> +{/if} 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 + }; + } +}; diff --git a/client/src/routes/+page.svelte b/client/src/routes/+page.svelte deleted file mode 100644 index cc88df0..0000000 --- a/client/src/routes/+page.svelte +++ /dev/null @@ -1,2 +0,0 @@ -<h1>Welcome to SvelteKit</h1> -<p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p> diff --git a/client/src/routes/login/+page.server.ts b/client/src/routes/login/+page.server.ts new file mode 100644 index 0000000..738b8ad --- /dev/null +++ b/client/src/routes/login/+page.server.ts @@ -0,0 +1,36 @@ +import { redirect } from '@sveltejs/kit'; +import { base } from '$app/paths'; +import type { Actions } from './$types'; +import { client } from '$lib/fetch-client'; + +export const actions = { + default: async ({ request, fetch }) => { + const data = await request.formData(); + const username = data.get('username'); + const password = data.get('password'); + const ret = data.get('return'); + + const login = await client.POST('/login', { + body: { + username: username?.toString() || '', + password: password?.toString() || '' + }, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + fetch + }); + if (login.data?.ok === true) { + if (ret) { + redirect(303, ret.toString()); + } else { + redirect(303, base); + } + } else { + return { + error: true, + username: username + }; + } + } +} satisfies Actions; diff --git a/client/src/routes/login/+page.svelte b/client/src/routes/login/+page.svelte new file mode 100644 index 0000000..8a91125 --- /dev/null +++ b/client/src/routes/login/+page.svelte @@ -0,0 +1,22 @@ +<script lang="ts"> + import type { PageProps } from './$types'; + + let { data, form }: PageProps = $props(); +</script> + +{#if form?.error} + <p>Unknown username or password</p> +{/if} + +<form method="POST"> + <label> + Username + <input name="username" type="text" value={form?.username} /> + </label> + <label> + Password + <input name="password" type="password" /> + </label> + <button>Log in</button> + <input type="hidden" name="return" value={data.return} /> +</form> diff --git a/client/src/routes/login/+page.ts b/client/src/routes/login/+page.ts new file mode 100644 index 0000000..70d306a --- /dev/null +++ b/client/src/routes/login/+page.ts @@ -0,0 +1,7 @@ +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ url }) => { + return { + return: url.searchParams.get('return') || '' + }; +}; |
