2024-03-29 22:52:42 +00:00
|
|
|
<script lang="ts">
|
2024-04-05 22:22:09 +00:00
|
|
|
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";
|
2024-04-03 22:59:05 +00:00
|
|
|
import type { DatabaseUser } from "$lib/server/auth";
|
2024-04-05 22:17:20 +00:00
|
|
|
export let user: any;
|
2024-04-06 01:59:10 +00:00
|
|
|
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");
|
|
|
|
}
|
2024-04-05 22:22:09 +00:00
|
|
|
async function toToLogin() {
|
|
|
|
goto("/login");
|
|
|
|
}
|
2024-04-06 01:59:10 +00:00
|
|
|
async function toToSignup() {
|
|
|
|
goto("/signup");
|
|
|
|
}
|
2024-04-02 18:28:14 +00:00
|
|
|
|
2024-04-02 22:02:20 +00:00
|
|
|
let count = 0;
|
|
|
|
visitCount.subscribe((value) => {
|
|
|
|
count = value;
|
|
|
|
});
|
2024-04-02 18:28:14 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2024-03-29 22:52:42 +00:00
|
|
|
</script>
|
2024-04-02 22:02:20 +00:00
|
|
|
|
2024-04-01 21:35:21 +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
|
|
|
|
>
|
2024-04-06 12:54:17 +00:00
|
|
|
{#if user}
|
|
|
|
<button
|
|
|
|
class="btn btn-primary my-2 md:my-0 md:mr-4 md:ml-2"
|
|
|
|
on:click={goToLog}>My Log</button
|
|
|
|
>
|
|
|
|
{/if}
|
2024-04-02 22:02:20 +00:00
|
|
|
<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>
|
2024-04-05 22:22:09 +00:00
|
|
|
{#if !user}
|
|
|
|
<button class="btn btn-primary ml-4" on:click={toToLogin}>Login</button>
|
2024-04-06 01:59:10 +00:00
|
|
|
<button class="btn btn-primary ml-4" on:click={toToSignup}>Signup</button>
|
2024-04-05 22:22:09 +00:00
|
|
|
{/if}
|
2024-04-05 22:17:20 +00:00
|
|
|
{#if user}
|
2024-04-06 01:59:10 +00:00
|
|
|
<UserAvatar {user} />
|
2024-04-06 12:27:42 +00:00
|
|
|
<form method="post" action="/" use:enhance>
|
|
|
|
<button class="btn btn-primary ml-4">Logout</button>
|
2024-04-05 22:22:09 +00:00
|
|
|
</form>
|
2024-04-05 22:17:20 +00:00
|
|
|
{/if}
|
2024-04-02 22:02:20 +00:00
|
|
|
</div>
|
2024-04-01 21:35:21 +00:00
|
|
|
</div>
|