Update Navbar component to display visit count

This commit is contained in:
Sean Morley
2024-04-02 18:28:14 +00:00
parent 4b2306f812
commit ad568bb3fa
3 changed files with 28 additions and 6 deletions

View File

@@ -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) {