This commit is contained in:
MuslemRahimi 2025-03-12 14:05:06 +01:00
parent 4536a47e7b
commit cf0f9f79ca
3 changed files with 19 additions and 31 deletions

View File

@ -96,7 +96,7 @@
<div class="fixed z-100 bottom-8 sm:bottom-10 right-8 sm:right-16"> <div class="fixed z-100 bottom-8 sm:bottom-10 right-8 sm:right-16">
<label <label
for="feedbackInfo" for="feedbackInfo"
class="border border-gray-300 inline-flex items-center justify-center w-12 h-12 sm:w-full sm:h-10 font-semibold bg-gray-400 dark:border-gray-700 dark:bg-primary shadow-xl ml-1 mr-0 sm:mr-2 rounded-full cursor-pointer" class="border border-gray-300 inline-flex items-center justify-center w-12 h-12 sm:w-full sm:h-10 font-semibold bg-gray-400 dark:border-gray-700 shadow-xl ml-1 mr-0 sm:mr-2 rounded-full cursor-pointer"
> >
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"

View File

@ -1,15 +1,12 @@
import { setMode, } from "mode-watcher";
export const load = ({ locals, cookies }) => { export const load = ({ locals, cookies }) => {
const { user, isUSRegion, wsURL } = locals; const { user, isUSRegion, wsURL } = locals;
const themeMode = cookies.get("theme-mode") || "dark"; // Default to dark
setMode(cookies?.get("theme-mode"));
return { return {
user: user || undefined, user: user || undefined,
isUSRegion, isUSRegion,
cookieConsent: cookies?.get("cookie-consent"), cookieConsent: cookies.get("cookie-consent"),
wsURL, wsURL,
themeMode // Add theme mode to returned data
}; };
}; };

View File

@ -125,6 +125,7 @@
typeof data?.cookieConsent !== "undefined" ? false : true; typeof data?.cookieConsent !== "undefined" ? false : true;
onMount(async () => { onMount(async () => {
setMode(data.themeMode);
if (data?.user?.id) { if (data?.user?.id) {
await loadWorker(); await loadWorker();
/* /*
@ -240,30 +241,20 @@
async function handleModeChange() { async function handleModeChange() {
if ($mode === "light") { const newMode = $mode === "light" ? "dark" : "light";
setMode("dark"); setMode(newMode);
} else { try {
setMode("light"); await fetch("/api/theme-mode", {
} method: "POST",
headers: { "Content-Type": "application/json" },
const postData = { body: JSON.stringify({ mode: newMode })
mode: $mode, });
}; } catch (error) {
console.error("Failed to update theme:", error);
const response = await fetch("/api/theme-mode", { }
method: "POST", }
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postData),
}); // make a POST request to the server with the FormData object
const output = await response.json();
console.log(output)
}
</script> </script>
<svelte:window bind:innerWidth={$screenWidth} /> <svelte:window bind:innerWidth={$screenWidth} />