diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index f05c718..d377bb2 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -5,6 +5,7 @@ import type { DatabaseUser } from "$lib/server/auth"; export let user: any; import UserAvatar from "./UserAvatar.svelte"; + import { onMount } from "svelte"; async function goHome() { goto("/"); } @@ -22,6 +23,15 @@ } let count = 0; + + // get value from fetch /api/visitcount + + onMount(async () => { + const res = await fetch("/api/visitcount"); + const data = await res.json(); + visitCount.set(data.visitCount); + }); + visitCount.subscribe((value) => { count = value; }); @@ -30,10 +40,6 @@ const isBrowser = typeof window !== "undefined"; if (isBrowser) { const storedAdventures = localStorage.getItem("adventures"); - if (storedAdventures) { - let parsed = JSON.parse(storedAdventures); - visitCount.set(parsed.length); - } } @@ -57,12 +63,12 @@ AdventureLog 🗺️