Update theme handling and add theme selection dropdown in Navbar.svelte

This commit is contained in:
Sean Morley
2024-04-17 00:01:19 +00:00
parent 3892a3ea39
commit b76e655e38
7 changed files with 55 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ import { fail, redirect } from "@sveltejs/kit";
import type { Actions, PageServerLoad } from "./$types";
export const load: PageServerLoad = async (event) => {
export const load: PageServerLoad = async (event: { locals: { user: any; }; }) => {
if (event.locals.user)
return {
user: event.locals.user,
@@ -15,7 +15,7 @@ export const load: PageServerLoad = async (event) => {
// handle the logout action
export const actions: Actions = {
default: async (event) => {
logout: async (event) => {
if (!event.locals.session) {
return fail(401);
}
@@ -28,4 +28,13 @@ export const actions: Actions = {
});
return redirect(302, "/login");
},
setTheme: async ( { url, cookies }) => {
const theme = url.searchParams.get("theme");
if (theme) {
cookies.set("colortheme", theme, {
path: "/",
maxAge: 60 * 60 * 24 * 365,
});
}
},
};

View File

@@ -17,7 +17,7 @@
});
if (response.ok) {
// wait .5s before redirecting
errors = {};
goto("/login");
return;
}