flotilla/src/routes/spaces/[relay]/+layout.svelte

47 lines
1.3 KiB
Svelte
Raw Normal View History

2024-08-16 19:42:00 +00:00
<script lang="ts">
2024-11-14 20:16:44 +00:00
import {onMount} from "svelte"
2024-08-16 22:17:30 +00:00
import {page} from "$app/stores"
2024-08-16 19:42:00 +00:00
import Page from "@lib/components/Page.svelte"
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
2024-10-21 21:35:12 +00:00
import MenuSpace from "@app/components/MenuSpace.svelte"
2024-11-07 23:19:19 +00:00
import {pushToast} from "@app/toast"
2024-11-14 18:53:13 +00:00
import {setChecked} from "@app/notifications"
2024-11-07 23:19:19 +00:00
import {checkRelayConnection, checkRelayAuth} from "@app/commands"
2024-11-13 01:44:29 +00:00
import {decodeRelay} from "@app/state"
2024-11-14 20:16:44 +00:00
import {deriveNotification, SPACE_FILTERS} from "@app/notifications"
2024-08-16 19:42:00 +00:00
2024-11-14 20:16:44 +00:00
const url = decodeRelay($page.params.relay)
const notification = deriveNotification($page.url.pathname, SPACE_FILTERS, url)
const ifLet = <T,>(x: T | undefined, f: (x: T) => void) => (x === undefined ? undefined : f(x))
2024-11-07 23:19:19 +00:00
const checkConnection = async () => {
ifLet(await checkRelayConnection(url), error => {
pushToast({theme: "error", message: error})
})
ifLet(await checkRelayAuth(url), error => {
pushToast({theme: "error", message: error})
})
}
2024-11-14 20:16:44 +00:00
// We have to watch this one, since on mobile the badge wil be visible when active
$: {
if ($notification) {
setChecked($page.url.pathname)
}
}
onMount(() => {
2024-11-07 23:19:19 +00:00
checkConnection()
})
2024-08-16 19:42:00 +00:00
</script>
2024-11-14 20:16:44 +00:00
<SecondaryNav>
<MenuSpace {url} />
</SecondaryNav>
<Page>
<slot />
</Page>