1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-29 01:39:36 +02:00

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

@ -1,5 +1,5 @@
<script lang="ts">
import { getNumberOfAdventures } from "../../services/adventureService";
import { visitCount } from '$lib/utils/stores/visitCountStore';
import { goto } from '$app/navigation';
async function goHome() {
@ -11,6 +11,23 @@
async function goToFeatured() {
goto('/featured');
}
let count = 0;
visitCount.subscribe((value) => {
count = value;
});
// Set the visit count to the number of adventures stored in local storage
const isBrowser = typeof window !== 'undefined';
if (isBrowser) {
const storedAdventures = localStorage.getItem('adventures');
if (storedAdventures) {
let parsed = JSON.parse(storedAdventures);
visitCount.set (parsed.length);
}
}
</script>
<div class="navbar bg-base-100 flex flex-col md:flex-row">
<div class="navbar-start flex justify-around md:justify-start">
@ -22,6 +39,6 @@
<a class="btn btn-ghost text-xl" href="/">AdventureLog 🗺️</a>
</div>
<div class="navbar-end flex justify-around md:justify-end mr-4">
<p>Adventures: {getNumberOfAdventures()} </p>
<p>Adventures: {count} </p>
</div>
</div>