2022-01-28 05:27:12 +00:00
|
|
|
<script lang="ts">
|
2023-09-18 09:42:09 +00:00
|
|
|
import { applyAction, enhance } from '$app/forms';
|
2024-02-17 00:38:02 +00:00
|
|
|
import toast from 'svelte-french-toast';
|
2024-03-08 19:03:34 +00:00
|
|
|
import { ListChecks, ListTodo, LogOut, User } from 'lucide-svelte';
|
2024-04-23 21:35:51 +00:00
|
|
|
import * as DropdownMenu from '$components/ui/dropdown-menu';
|
|
|
|
|
import * as Avatar from '$components/ui/avatar';
|
2023-09-18 09:42:09 +00:00
|
|
|
import { invalidateAll } from '$app/navigation';
|
2024-02-17 00:38:02 +00:00
|
|
|
import Logo from '$components/logo.svelte';
|
2024-05-08 00:19:13 +00:00
|
|
|
import type { Users } from '$db/schema';
|
2023-05-21 05:18:04 +00:00
|
|
|
|
2024-03-11 06:19:55 +00:00
|
|
|
export let user: Users | null = null;
|
|
|
|
|
|
|
|
|
|
console.log('header user', user);
|
2023-09-08 23:30:32 +00:00
|
|
|
|
2024-03-07 04:37:05 +00:00
|
|
|
let avatar: string;
|
|
|
|
|
|
|
|
|
|
$: if (user) {
|
2024-03-21 19:27:32 +00:00
|
|
|
avatar = user.username?.slice(0, 1).toUpperCase() || ':)';
|
2024-03-07 04:37:05 +00:00
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<header>
|
2022-10-31 19:06:27 +00:00
|
|
|
<div class="corner">
|
2024-02-17 00:38:02 +00:00
|
|
|
<a href="/" title="Home">
|
2024-02-16 01:18:37 +00:00
|
|
|
<div class="logo-image">
|
2023-11-13 06:04:44 +00:00
|
|
|
<Logo />
|
|
|
|
|
</div>
|
2024-03-21 19:27:32 +00:00
|
|
|
<span class="logo-text">Bored Game</span>
|
2022-10-31 19:06:27 +00:00
|
|
|
</a>
|
|
|
|
|
</div>
|
2023-01-17 07:07:15 +00:00
|
|
|
<!-- <TextSearch /> -->
|
2022-10-31 19:06:27 +00:00
|
|
|
<nav>
|
2024-03-11 06:19:55 +00:00
|
|
|
{#if user}
|
2023-09-17 21:28:15 +00:00
|
|
|
<DropdownMenu.Root>
|
|
|
|
|
<DropdownMenu.Trigger>
|
2023-09-08 23:30:32 +00:00
|
|
|
<Avatar.Root asChild>
|
|
|
|
|
<Avatar.Fallback class="text-3xl font-medium text-magnum-700 h-16 w-16 bg-neutral-100">
|
|
|
|
|
{avatar}
|
|
|
|
|
</Avatar.Fallback>
|
|
|
|
|
</Avatar.Root>
|
2023-09-17 21:28:15 +00:00
|
|
|
</DropdownMenu.Trigger>
|
|
|
|
|
<DropdownMenu.Content>
|
|
|
|
|
<DropdownMenu.Group>
|
|
|
|
|
<DropdownMenu.Label>My Account</DropdownMenu.Label>
|
|
|
|
|
<DropdownMenu.Separator />
|
2023-09-18 00:09:44 +00:00
|
|
|
<a href="/profile">
|
|
|
|
|
<DropdownMenu.Item>
|
|
|
|
|
<User class="mr-2 h-4 w-4" />
|
|
|
|
|
<span>Profile</span>
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
</a>
|
2024-04-23 21:35:51 +00:00
|
|
|
<a href="/collections">
|
2023-09-18 00:09:44 +00:00
|
|
|
<DropdownMenu.Item>
|
|
|
|
|
<ListChecks class="mr-2 h-4 w-4" />
|
2024-04-23 21:35:51 +00:00
|
|
|
<span>Collections</span>
|
2023-09-18 00:09:44 +00:00
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
</a>
|
2024-04-23 21:35:51 +00:00
|
|
|
<a href="/wishlists">
|
2023-09-18 00:09:44 +00:00
|
|
|
<DropdownMenu.Item>
|
|
|
|
|
<ListTodo class="mr-2 h-4 w-4" />
|
2024-04-23 21:35:51 +00:00
|
|
|
<span>Wishlists</span>
|
2023-09-18 00:09:44 +00:00
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
</a>
|
|
|
|
|
<form
|
2023-09-18 09:42:09 +00:00
|
|
|
use:enhance={() => {
|
|
|
|
|
return async ({ result }) => {
|
|
|
|
|
console.log(result);
|
|
|
|
|
if (result.type === 'success' || result.type === 'redirect') {
|
|
|
|
|
toast.success('Logged Out');
|
|
|
|
|
} else if (result.type === 'error') {
|
|
|
|
|
console.log(result);
|
|
|
|
|
toast.error(`Error: ${result.error.message}`);
|
|
|
|
|
} else {
|
|
|
|
|
toast.error(`Something went wrong.`);
|
|
|
|
|
console.log(result);
|
|
|
|
|
}
|
|
|
|
|
await invalidateAll();
|
|
|
|
|
await applyAction(result);
|
|
|
|
|
};
|
|
|
|
|
}}
|
2023-09-18 00:09:44 +00:00
|
|
|
action="/logout"
|
|
|
|
|
method="POST"
|
|
|
|
|
>
|
|
|
|
|
<button type="submit" class="">
|
|
|
|
|
<DropdownMenu.Item>
|
2024-04-23 21:35:51 +00:00
|
|
|
<div class="flex items-center gap-1">
|
|
|
|
|
<LogOut class="mr-2 h-4 w-4" />
|
|
|
|
|
<span>Sign out</span>
|
|
|
|
|
</div>
|
2023-09-18 00:09:44 +00:00
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
</button>
|
|
|
|
|
</form>
|
2023-09-17 21:28:15 +00:00
|
|
|
</DropdownMenu.Group>
|
|
|
|
|
</DropdownMenu.Content>
|
|
|
|
|
</DropdownMenu.Root>
|
2024-03-11 06:19:55 +00:00
|
|
|
{:else}
|
2024-04-23 21:35:51 +00:00
|
|
|
<a href="/login"> <span class="flex-auto">Login</span></a>
|
|
|
|
|
<a href="/sign-up"> <span class="flex-auto">Sign Up</span></a>
|
2023-05-24 06:28:23 +00:00
|
|
|
{/if}
|
2022-10-31 19:06:27 +00:00
|
|
|
</nav>
|
2022-01-28 05:27:12 +00:00
|
|
|
</header>
|
|
|
|
|
|
2023-06-16 06:28:49 +00:00
|
|
|
<style lang="postcss">
|
2022-10-31 19:06:27 +00:00
|
|
|
header {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: var(--containerPadding);
|
|
|
|
|
font-size: 1.6rem;
|
2022-07-21 06:20:32 +00:00
|
|
|
|
2022-10-31 19:06:27 +00:00
|
|
|
@media (max-width: 1000px) {
|
|
|
|
|
padding-top: 1.25rem;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
|
2022-10-31 19:06:27 +00:00
|
|
|
.corner {
|
2023-09-08 23:30:32 +00:00
|
|
|
margin-left: 1rem;
|
2022-10-31 19:06:27 +00:00
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
|
2022-10-31 19:06:27 +00:00
|
|
|
.corner a {
|
|
|
|
|
display: flex;
|
2024-02-16 01:18:37 +00:00
|
|
|
place-items: center;
|
|
|
|
|
gap: 0.5rem;
|
2022-10-31 19:06:27 +00:00
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
2024-02-16 01:18:37 +00:00
|
|
|
font-size: 1.125rem;
|
|
|
|
|
line-height: 1.75rem;
|
|
|
|
|
font-weight: 500;
|
2022-10-31 19:06:27 +00:00
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
|
2024-02-16 01:18:37 +00:00
|
|
|
.logo-image {
|
|
|
|
|
width: 2rem;
|
|
|
|
|
height: 2rem;
|
2024-03-21 19:27:32 +00:00
|
|
|
|
|
|
|
|
@media (width < 640px) {
|
|
|
|
|
width: 3rem;
|
|
|
|
|
height: 3rem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.logo-text {
|
|
|
|
|
@media (width < 640px) {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
2022-10-31 19:06:27 +00:00
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
|
2022-10-31 19:06:27 +00:00
|
|
|
nav {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
margin: 1rem;
|
|
|
|
|
--background: rgba(255, 255, 255, 0.7);
|
|
|
|
|
}
|
2022-05-03 02:31:50 +00:00
|
|
|
|
2022-10-31 19:06:27 +00:00
|
|
|
nav a {
|
|
|
|
|
color: var(--heading-color);
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
text-transform: uppercase;
|
|
|
|
|
letter-spacing: 0.1em;
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
transition: color 0.2s linear;
|
|
|
|
|
}
|
2022-05-03 02:31:50 +00:00
|
|
|
|
2022-10-31 19:06:27 +00:00
|
|
|
a:hover {
|
|
|
|
|
text-decoration: underline;
|
|
|
|
|
color: var(--accent-color);
|
|
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
</style>
|