1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-27 00:39:37 +02:00
AdventureLog/src/lib/components/Navbar.svelte

71 lines
2 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { enhance } from "$app/forms";
2024-04-02 22:02:20 +00:00
import { visitCount } from "$lib/utils/stores/visitCountStore";
import { goto } from "$app/navigation";
import type { DatabaseUser } from "$lib/server/auth";
2024-04-05 22:17:20 +00:00
export let user: any;
import UserAvatar from "./UserAvatar.svelte";
2024-04-02 22:02:20 +00:00
async function goHome() {
goto("/");
}
async function goToLog() {
goto("/log");
}
async function goToFeatured() {
goto("/featured");
}
async function toToLogin() {
goto("/login");
}
async function toToSignup() {
goto("/signup");
}
2024-04-02 22:02:20 +00:00
let count = 0;
visitCount.subscribe((value) => {
count = value;
});
2024-04-02 22:02:20 +00:00
// 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>
2024-04-02 22:02:20 +00:00
<div class="navbar bg-base-100 flex flex-col md:flex-row">
2024-04-02 22:02:20 +00:00
<div class="navbar-start flex justify-around md:justify-start">
<button
class="btn btn-primary my-2 md:my-0 md:mr-4 md:ml-2"
on:click={goHome}>Home</button
>
<button
class="btn btn-primary my-2 md:my-0 md:mr-4 md:ml-2"
on:click={goToLog}>My Log</button
>
<button class="btn btn-primary my-2 md:my-0" on:click={goToFeatured}
>Featured</button
>
</div>
<div class="navbar-center flex justify-center md:justify-center">
<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: {count}</p>
{#if !user}
<button class="btn btn-primary ml-4" on:click={toToLogin}>Login</button>
<button class="btn btn-primary ml-4" on:click={toToSignup}>Signup</button>
{/if}
2024-04-05 22:17:20 +00:00
{#if user}
<UserAvatar {user} />
<form method="post" action="/" use:enhance>
<button class="btn btn-primary ml-4">Logout</button>
</form>
2024-04-05 22:17:20 +00:00
{/if}
2024-04-02 22:02:20 +00:00
</div>
</div>