boredgame/src/routes/+layout.svelte

94 lines
2 KiB
Svelte
Raw Normal View History

2022-01-28 05:27:12 +00:00
<script lang="ts">
import "$lib/styles/app.pcss";
2023-09-12 00:29:15 +00:00
import { onMount } from "svelte";
import { getFlash } from 'sveltekit-flash-message/client';
import toast, { Toaster } from 'svelte-french-toast';
import { navigating, page } from '$app/stores';
import { MetaTags } from 'svelte-meta-tags';
2023-09-12 00:29:15 +00:00
import debounce from 'just-debounce-it';
import 'iconify-icon';
import Analytics from '$lib/components/analytics.svelte';
import { boredState } from '$lib/stores/boredState';
import { theme } from '$state/theme';
const dev = process.env.NODE_ENV !== 'production';
export let data;
$: ({ user } = data);
$: metaTags = {
titleTemplate: '%s | Bored Game',
description: 'Bored Game, keep track of your games.',
openGraph: {
type: 'website',
titleTemplate: '%s | Bored Game',
locale: 'en_US',
description: 'Bored Game, keep track of your games',
},
...$page.data.metaTagsChild
}
2023-09-12 00:29:15 +00:00
const flash = getFlash(page, {
clearAfterMs: 6000
});
let flashType;
let flashMessage;
$: flashType = $flash?.type;
$: flashMessage = $flash?.message;
$: {
if ($navigating) {
debounce(() => {
boredState.update((n) => ({ ...n, loading: true }));
}, 250);
}
if (!$navigating) {
boredState.update((n) => ({ ...n, loading: false }));
}
}
$: isOpen = $boredState?.dialog?.isOpen;
onMount(() => {
// set the theme to the user's active theme
$theme = user?.theme || 'system';
document.querySelector('html')?.setAttribute('data-theme', $theme);
});
flash.subscribe(($flash) => {
if (!$flash) return;
if ($flash.type == 'success') {
toast.success($flash.message);
} else {
toast.error($flash.message, {
duration: 5000
});
}
// Clearing the flash message could sometimes
// be required here to avoid double-toasting.
flash.set(undefined);
});
2022-01-28 05:27:12 +00:00
</script>
2023-09-12 00:29:15 +00:00
{#if !dev}
<Analytics />
{/if}
<MetaTags {...metaTags} />
2023-09-12 00:29:15 +00:00
<div class="layout">
<slot />
2023-09-12 00:29:15 +00:00
</div>
<Toaster />
<style lang="postcss">
.layout {
display: flex;
position: relative;
flex-direction: column;
min-height: 100vh;
}
</style>