aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/+layout.svelte
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-08-16 15:31:41 -0700
committerAdam Soltys <[email protected]>2022-08-16 15:31:41 -0700
commit770725fbdcc8ea7bf47ef0af5a43a239bef98ff6 (patch)
tree445d55b896a63eab5a29204e720a9e74d0629697 /src/routes/+layout.svelte
parent0b51e1dfd0d099c243d21889fb77fea4769dac0a (diff)
downloadcoinos-ui-770725fbdcc8ea7bf47ef0af5a43a239bef98ff6.tar.gz
coinos-ui-770725fbdcc8ea7bf47ef0af5a43a239bef98ff6.zip
sveltekit route migration
Diffstat (limited to 'src/routes/+layout.svelte')
-rw-r--r--src/routes/+layout.svelte57
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>