Use localStorage for green
This commit is contained in:
parent
2650d024db
commit
7a882942e6
5 changed files with 22 additions and 22 deletions
|
@ -1,7 +0,0 @@
|
|||
export async function load({ cookies }) {
|
||||
const green = cookies.get("green");
|
||||
|
||||
return {
|
||||
green: green === "true"
|
||||
};
|
||||
}
|
|
@ -1,14 +1,17 @@
|
|||
<script>
|
||||
import { browser } from "$app/environment";
|
||||
import { page } from "$app/stores";
|
||||
import Footer from "$lib/components/Footer.svelte";
|
||||
import Navbar from "$lib/components/Navbar.svelte";
|
||||
import "./style.css";
|
||||
|
||||
export let data;
|
||||
const green = browser
|
||||
? window.localStorage.getItem("green") === "true"
|
||||
: false;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
{#if data.green}
|
||||
{#if green}
|
||||
<link rel="stylesheet" href="/assets/green.css" />
|
||||
{/if}
|
||||
<title>
|
||||
|
|
16
src/routes/green/+page.js
Normal file
16
src/routes/green/+page.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { browser } from '$app/environment';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export async function load() {
|
||||
if (!browser) return;
|
||||
|
||||
const green = window.localStorage.getItem("green");
|
||||
|
||||
if (green === "true") {
|
||||
window.localStorage.removeItem("green");
|
||||
} else {
|
||||
window.localStorage.setItem("green", "true");
|
||||
}
|
||||
|
||||
redirect(302, "/");
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export async function load({ cookies }) {
|
||||
const green = cookies.get("green");
|
||||
|
||||
if (green === "true") {
|
||||
cookies.delete("green", { path: "/" });
|
||||
} else {
|
||||
cookies.set("green", "true", { path: "/", sameSite: "strict" });
|
||||
}
|
||||
|
||||
redirect(302, "/");
|
||||
}
|
1
src/routes/green/+page.svelte
Normal file
1
src/routes/green/+page.svelte
Normal file
|
@ -0,0 +1 @@
|
|||
<p>Toggling green...</p>
|
Loading…
Reference in a new issue