flotilla/src/routes/+layout.svelte

88 lines
2 KiB
Svelte
Raw Normal View History

2024-08-05 21:45:16 +00:00
<script lang="ts">
2024-08-06 20:10:10 +00:00
import "@src/app.css"
2024-08-09 00:22:17 +00:00
import {onMount} from 'svelte'
2024-08-05 22:28:46 +00:00
import {page} from "$app/stores"
2024-08-14 19:46:25 +00:00
import {createEventStore} from '@welshman/store'
2024-08-06 22:46:37 +00:00
import {fly} from "@lib/transition"
2024-08-08 21:02:46 +00:00
import ModalBox from "@lib/components/ModalBox.svelte"
2024-08-08 23:32:46 +00:00
import Toast from "@app/components/Toast.svelte"
2024-08-09 23:22:09 +00:00
import Landing from "@app/components/Landing.svelte"
2024-08-06 20:10:10 +00:00
import PrimaryNav from "@app/components/PrimaryNav.svelte"
import SecondaryNav from "@app/components/SecondaryNav.svelte"
2024-08-09 00:22:17 +00:00
import {modals, clearModal} from "@app/modal"
2024-08-14 19:46:25 +00:00
import {session, sessions, pk, repository} from "@app/base"
import {plaintext, relays, handles} from "@app/state"
import {initStorage} from "@app/storage"
2024-08-05 21:45:16 +00:00
2024-08-14 19:46:25 +00:00
let ready: Promise<void>
2024-08-09 00:22:17 +00:00
let dialog: HTMLDialogElement
2024-08-14 00:58:26 +00:00
let prev: any
2024-08-09 00:22:17 +00:00
2024-08-09 23:22:09 +00:00
$: modalId = $page.url.hash.slice(1)
$: modal = modals.get(modalId)
2024-08-05 21:45:16 +00:00
$: {
2024-08-09 23:22:09 +00:00
if (!modal && !$session) {
modal = {component: Landing}
}
2024-08-09 00:22:17 +00:00
if (modal) {
dialog?.showModal()
2024-08-14 00:58:26 +00:00
prev = modal
2024-08-05 21:45:16 +00:00
} else {
2024-08-09 00:22:17 +00:00
dialog?.close()
2024-08-05 21:45:16 +00:00
}
}
2024-08-09 00:22:17 +00:00
onMount(() => {
2024-08-14 19:46:25 +00:00
ready = initStorage({
events: {
keyPath: 'id',
store: createEventStore(repository),
},
relays: {
keyPath: 'url',
store: relays,
},
handles: {
keyPath: 'nip05',
store: handles,
},
})
2024-08-09 00:22:17 +00:00
dialog.addEventListener('close', () => {
if (modal) {
clearModal()
}
})
})
2024-08-05 21:45:16 +00:00
</script>
2024-08-14 19:46:25 +00:00
{#await ready}
<div data-theme="dark" />
{:then}
<div data-theme="dark">
<div class="flex h-screen">
<PrimaryNav />
<SecondaryNav />
<div class="flex-grow bg-base-200">
<slot />
</div>
2024-08-08 21:02:46 +00:00
</div>
2024-08-14 19:46:25 +00:00
<dialog bind:this={dialog} class="modal modal-bottom sm:modal-middle !z-modal">
{#if prev}
{#key prev}
<ModalBox {...prev} />
{/key}
<Toast />
{/if}
{#if $session}
<form method="dialog" class="modal-backdrop">
<button />
</form>
{/if}
</dialog>
<Toast />
2024-08-05 21:45:16 +00:00
</div>
2024-08-14 19:46:25 +00:00
{/await}