diff options
| author | Adam Soltys <[email protected]> | 2022-11-02 19:47:29 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-11-02 19:48:18 -0700 |
| commit | 23ffc5a6359dbc84a1de1da632412edeb9989b5f (patch) | |
| tree | 1cc276efeb5287e1fc176ec60d46aed091ab08ca /src/routes/(app)/+layout.svelte | |
| parent | c12857a38eed1227ed51dc6e0af7242e66dd7561 (diff) | |
| download | coinos-ui-23ffc5a6359dbc84a1de1da632412edeb9989b5f.tar.gz coinos-ui-23ffc5a6359dbc84a1de1da632412edeb9989b5f.zip | |
move to app layout
Diffstat (limited to 'src/routes/(app)/+layout.svelte')
| -rw-r--r-- | src/routes/(app)/+layout.svelte | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte new file mode 100644 index 00000000..10b16449 --- /dev/null +++ b/src/routes/(app)/+layout.svelte @@ -0,0 +1,87 @@ +<script> + import { SvelteToast } from '@zerodevx/svelte-toast'; + import { onDestroy, onMount } from 'svelte'; + import { close, connect, send } from '$lib/socket'; + import { last, selectedRate, rate, user } from '$lib/store'; + import { page } from '$app/stores'; + import { browser } from '$app/environment'; + import { goto } from '$app/navigation'; + import { LoadingSplash } from '$comp'; + import { warning, protectedRoutes } from '$lib/utils'; + import { t, locale } from '$lib/translations'; + + const localeLocalStorageKey = 'sveltekit-i18n-locale'; + + export let data; + + let { subject } = $page.data; + let r, u, token, rates; + + $: update(data); + let update = () => { + ({ user: u, rate: r, token, rates } = data); + $rate = r; + $user = u; + }; + + $: $page.url.searchParams.get('logout') && close(); + + $: $selectedRate = r * (rates[u?.currency || 'USD'] / rates.USD); + + onMount(() => { + let localStorageLocale = localStorage.getItem(localeLocalStorageKey); + if (localStorageLocale) locale.set(localStorageLocale); + + locale.subscribe((lng) => { + if (lng) localStorage.setItem(localeLocalStorageKey, lng); + }); + + browser && checkSocket(); + }); + + $: browser && connect(token); + + let lost, + timer, + counter = 0; + + let checkSocket = () => { + counter++; + lost = Date.now() - $last > 15000; + if (lost) close(); + if (counter > 5) { + send('heartbeat'); + counter = 0; + } + timer = setTimeout(checkSocket, 1000); + }; + + onDestroy(() => browser && clearTimeout(timer)); +</script> + +<svelte:head> + {#if subject} + <title>coinos - {subject.username}</title> + <meta name="lightning" content={`lnurlp:${subject.username}@coinos.io`} /> + {:else} + <title>coinos</title> + {/if} + + {#if subject?.profile} + <meta name="og:image" content={`/api/public/${subject.username}-profile.webp`} /> + {:else} + <meta property="og:image" content="/icons/logo.svg" /> + {/if} +</svelte:head> + +<SvelteToast options={{ reversed: true, intro: { y: 192 } }} /> + +{#if lost} + <div class="fixed bottom-12 right-12 text-red-600 bg-white z-50 px-4 py-2 rounded-full border"> + Lost connection to server, try refreshing + </div> +{/if} + +<main data-sveltekit-prefetch> + <slot /> +</main> |
