fix: use $app/state

This commit is contained in:
2025-12-30 11:20:39 -05:00
parent 1950dc47ae
commit b44f0bce0a
@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { user } from '$lib/stores/user'; import { user } from '$lib/stores/user';
import { resolve } from '$app/paths'; import { resolve } from '$app/paths';
import { page } from '$app/stores'; import { page } from '$app/state';
function logout() { function logout() {
localStorage.removeItem('token'); localStorage.removeItem('token');
@@ -10,32 +10,35 @@
window.location.href = '/'; window.location.href = '/';
} }
$: currentPath = $page.url.pathname; $: currentPath = page.url.pathname;
$: returnParam = currentPath !== '/' ? `?return=${encodeURIComponent($page.url.pathname + $page.url.search)}` : ''; $: returnParam =
currentPath !== '/' ? `?return=${encodeURIComponent(page.url.pathname + page.url.search)}` : '';
</script> </script>
<div class="fixed top-0 left-0 h-15 w-full bg-neutral-900 z-100"> <div class="fixed top-0 left-0 z-100 h-15 w-full bg-neutral-900">
<div class="mx-auto flex h-15 max-w-5xl items-center px-4 py-2"> <div class="mx-auto flex h-15 max-w-5xl items-center px-4 py-2">
<a href={resolve('/')} class="text-xl font-bold text-white hover:text-neutral-300">Sharpbin</a> <a href={resolve('/')} class="text-xl font-bold text-white hover:text-neutral-300">Sharpbin</a>
{#if $user} {#if $user}
<div class="ml-auto flex items-center space-x-4"> <div class="ml-auto flex items-center space-x-4">
<a <a
href={resolve(`/user/${$user.username}`)} href={resolve(`/user/${$user.username}`)}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800" class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Profile</a
>Profile</a
> >
<button <button
on:click={logout} on:click={logout}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800 cursor-pointer">Logout</button class="cursor-pointer rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800"
>Logout</button
> >
</div> </div>
{:else} {:else}
<div class="ml-auto flex items-center space-x-4"> <div class="ml-auto flex items-center space-x-4">
<a href={resolve('/login') + returnParam} class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800" <a
>Login</a href={resolve(`/login${returnParam}`)}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Login</a
> >
<a href={resolve('/register') + returnParam} class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800" <a
>Register</a href={resolve(`/register${returnParam}`)}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Register</a
> >
</div> </div>
{/if} {/if}