diff options
| author | Adam Soltys <[email protected]> | 2022-08-16 15:31:41 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-08-16 15:31:41 -0700 |
| commit | 0b8e3ce07154cc1609bc90f829fa7237a259c7f9 (patch) | |
| tree | 0c9d6361c1a1eee28eea70517fab1bbf8675a440 /src/routes/+layout.svelte | |
| parent | 3b9a2b884dcaf8f33258bfee03d5c9e0e5ecb56a (diff) | |
| download | coinos-ui-0b8e3ce07154cc1609bc90f829fa7237a259c7f9.tar.gz coinos-ui-0b8e3ce07154cc1609bc90f829fa7237a259c7f9.zip | |
sveltekit route migration
Diffstat (limited to 'src/routes/+layout.svelte')
| -rw-r--r-- | src/routes/+layout.svelte | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte new file mode 100644 index 00000000..316bf6b3 --- /dev/null +++ b/src/routes/+layout.svelte @@ -0,0 +1,57 @@ +<script> + import { SvelteToast } from '@zerodevx/svelte-toast'; + import '$lib/i18n'; + import { isLoading, locale } from 'svelte-i18n'; + import '../app.css'; + import { onMount } from 'svelte'; + import { connect } from '$lib/socket'; + import { user, token } from '$lib/store'; + import { page, session } from '$app/stores'; + import { browser } from '$app/env'; + import { goto } from '$app/navigation'; + import { LoadingSplash } from '$comp'; + import { warning, protectedRoutes } from '$lib/utils'; + + browser && ($token ||= $session.token); + + let ready = false; + + onMount(() => { + // get locale from local storage + let localStorageLocale = localStorage.getItem('svelte-i18n-locale'); + if (localStorageLocale) locale.set(localStorageLocale); + + locale.subscribe((lng) => { + if (lng) localStorage.setItem('svelte-i18n-locale', lng); + }); + + if (protectedRoutes.find((p) => $page.url.pathname.match(p))) { + if (!$token) { + goto('/login'); + warning('Please sign in to continue.'); + } + user.subscribe((u) => u?.username && (ready = true)); + } else { + ready = true; + } + + connect(); + }); +</script> + +{#if ready && !$isLoading} + <SvelteToast options={{ reversed: true, intro: { y: 192 } }} /> + <slot /> +{:else} + <LoadingSplash /> +{/if} + +<style> + :root { + --toastContainerTop: auto; + --toastContainerRight: auto; + --toastContainerBottom: 8rem; + --toastContainerLeft: calc(50vw - 8rem); + --toastBackground: #292929; + } +</style> |
