diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index 27473bf..1df7f89 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -1,5 +1,5 @@ diff --git a/src/lib/utils/stores/visitCountStore.ts b/src/lib/utils/stores/visitCountStore.ts new file mode 100644 index 0000000..347f1fc --- /dev/null +++ b/src/lib/utils/stores/visitCountStore.ts @@ -0,0 +1,4 @@ +import { onMount } from "svelte"; +import { writable } from "svelte/store"; + +export const visitCount = writable(0); diff --git a/src/services/adventureService.ts b/src/services/adventureService.ts index 319996e..e4456df 100644 --- a/src/services/adventureService.ts +++ b/src/services/adventureService.ts @@ -2,9 +2,12 @@ import type { Adventure } from '$lib/utils/types'; let adventures: Adventure[] = []; +import { visitCount } from '$lib/utils/stores/visitCountStore'; + // Check if localStorage is available (browser environment) const isBrowser = typeof window !== 'undefined'; + // Load adventures from localStorage on startup (only in the browser) if (isBrowser) { const storedAdventures = localStorage.getItem('adventures'); @@ -28,6 +31,7 @@ export function addAdventure(adventure: Adventure) { localStorage.setItem('adventures', JSON.stringify(adventures)); } console.log(adventures); + visitCount.update((n) => n + 1); } export function getAdventures(): Adventure[] { @@ -39,6 +43,7 @@ export function removeAdventure(event: { detail: number; }) { if (isBrowser) { localStorage.setItem('adventures', JSON.stringify(adventures)); } + visitCount.update((n) => n - 1); } export function saveEdit(adventure:Adventure) { @@ -61,10 +66,6 @@ export function saveEdit(adventure:Adventure) { } } -export function getNumberOfAdventures() { - return adventures.length; -} - export function clearAdventures() { adventures = []; if (isBrowser) {