|
1 | 1 | <script lang="ts"> |
2 | | - import { dev } from '$app/environment'; |
3 | | - import { goto } from '$app/navigation'; |
4 | | - import api from '$endpoints'; |
5 | | - import type { ConfigJson } from '$lib/server/data/config'; |
6 | | - import Separator from '$components/Separator.svelte'; |
| 2 | + import { dev } from "$app/environment"; |
| 3 | + import { goto } from "$app/navigation"; |
| 4 | + import api from "$endpoints"; |
| 5 | + import type { ConfigJson } from "$lib/server/data/config"; |
| 6 | + import Separator from "$components/Separator.svelte"; |
7 | 7 |
|
8 | | - export let path: { url: string, txt: string }[]; |
| 8 | + export let path: { url: string; txt: string }[]; |
9 | 9 | export let config: ConfigJson; |
10 | 10 | /** Whether the user is logged in. Set to undefined if auth is disabled */ |
11 | 11 | export let loggedIn: boolean | undefined; |
|
16 | 16 | location.reload(); |
17 | 17 | } |
18 | 18 |
|
| 19 | + /** |
| 20 | + * Go to the login page, with the from parameter determining the origin page. |
| 21 | + */ |
| 22 | + async function gotoLogin() { |
| 23 | + await goto(`/admin/login?from=${window.location.pathname}`); |
| 24 | + } |
| 25 | +
|
19 | 26 | /** Clear all data, and take the user to the firstrun page */ |
20 | 27 | async function clear() { |
21 | 28 | await api().debug.clear(); |
22 | | - await goto('/admin/firstrun'); |
| 29 | + await goto("/admin/firstrun"); |
23 | 30 | } |
24 | 31 |
|
25 | 32 | // This function needs to accept `path` as an input, otherwise the links |
26 | 33 | // stop being reactive due to cacheing or something |
27 | | - function pathTo(path: { url: string, txt: string }[], i: number) { |
28 | | - return path.slice(0, i + 1).map(p => p.url).join('/'); |
| 34 | + function pathTo(path: { url: string; txt: string }[], i: number) { |
| 35 | + return path |
| 36 | + .slice(0, i + 1) |
| 37 | + .map((p) => p.url) |
| 38 | + .join("/"); |
29 | 39 | } |
30 | 40 | </script> |
31 | 41 |
|
|
38 | 48 | <a href="/">{config.siteShortName}</a> / |
39 | 49 | {#each path.slice(0, -1) as p, i} |
40 | 50 | <a href="/{pathTo(path, i)}">{p.txt}</a> |
41 | | - {'/ '} |
| 51 | + {"/ "} |
42 | 52 | {/each} |
43 | 53 | {path[path.length - 1].txt} |
44 | 54 | </h1> |
|
48 | 58 | <!-- Control buttons --> |
49 | 59 | <span id="control-buttons"> |
50 | 60 | {#if loggedIn} |
51 | | - <button on:click={() => goto('/admin')}> Admin </button> |
| 61 | + <button on:click={() => goto("/admin")}> Admin </button> |
52 | 62 | <button on:click={logOut}> Log out </button> |
53 | 63 | {:else if loggedIn !== undefined} |
54 | 64 | <!-- Only include a login button if logging in is enabled --> |
55 | | - <button on:click={() => goto('/admin/login')}> Log in </button> |
| 65 | + <button on:click={gotoLogin}> Log in </button> |
56 | 66 | {/if} |
57 | 67 | <!-- About button navigates to about page --> |
58 | | - <button on:click={() => goto('/about')}> About </button> |
| 68 | + <button on:click={() => goto("/about")}> About </button> |
59 | 69 | <!-- In dev mode, add a quick shortcut to delete everything --> |
60 | 70 | {#if dev} |
61 | 71 | <Separator /> |
|
0 commit comments