aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/__layout.svelte
diff options
context:
space:
mode:
authorAdrien Hopkins <[email protected]>2022-08-02 13:13:27 -0500
committerAdrien Hopkins <[email protected]>2022-08-02 13:13:27 -0500
commitc21ee41b206db79b2157d8743b0473a094448dfb (patch)
treefac1a595e451c0b32ceedfe4fb70855270456377 /src/routes/__layout.svelte
parent3b216dd6c170a7d71d21a391098c554008c8bdb4 (diff)
parent05f5001fc7d325e31d9c777be11343604c72fbfd (diff)
downloadcoinos-ui-c21ee41b206db79b2157d8743b0473a094448dfb.tar.gz
coinos-ui-c21ee41b206db79b2157d8743b0473a094448dfb.zip
Merge branch 'master' into i18n
Diffstat (limited to 'src/routes/__layout.svelte')
-rw-r--r--src/routes/__layout.svelte42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte
index ed1ad188..9ec36c57 100644
--- a/src/routes/__layout.svelte
+++ b/src/routes/__layout.svelte
@@ -1,11 +1,47 @@
<script>
+ import { SvelteToast } from '@zerodevx/svelte-toast';
+ import { toast } from '@zerodevx/svelte-toast';
import '../app.css';
+ import '$lib/i18n';
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 { protectedRoutes } from '$lib/utils';
- import '$lib/i18n';
+ browser && ($token ||= $session.token);
+ let ready = false;
- onMount(connect);
+ onMount(() => {
+ if (protectedRoutes.find((p) => $page.url.pathname.match(p))) {
+ if (!$token) {
+ goto('/login');
+ toast.push('Please sign in to continue.');
+ }
+ user.subscribe((u) => u?.username && (ready = true));
+ } else {
+ ready = true;
+ }
+
+ connect();
+ });
</script>
-<slot />
+{#if ready}
+ <SvelteToast options={{ reversed: true, intro: { y: 192 } }} />
+ <slot />
+{:else}
+ <LoadingSplash />
+{/if}
+
+<style>
+ :root {
+ --toastContainerTop: auto;
+ --toastContainerRight: auto;
+ --toastContainerBottom: 8rem;
+ --toastContainerLeft: calc(50vw - 8rem);
+ }
+</style>