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

65 lines
1.8 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-11-19 04:31:17 +00:00
import {now} from "@welshman/lib"
2024-11-15 22:03:54 +00:00
import {subscribe} from "@welshman/app"
import {DELETE, REACTION} from "@welshman/util"
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-19 04:31:17 +00:00
import SpaceAuthError from "@app/components/SpaceAuthError.svelte"
2024-11-07 23:19:19 +00:00
import {pushToast} from "@app/toast"
2024-11-19 04:31:17 +00:00
import {pushModal} from "@app/modal"
2024-11-14 18:53:13 +00:00
import {setChecked} from "@app/notifications"
2024-11-19 04:31:17 +00:00
import {checkRelayConnection, checkRelayAuth, checkRelayAccess} from "@app/commands"
2024-11-15 22:03:54 +00:00
import {decodeRelay, MEMBERSHIPS} 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)
2024-11-07 23:19:19 +00:00
const checkConnection = async () => {
2024-11-19 04:31:17 +00:00
const connectionError = await checkRelayConnection(url)
2024-11-07 23:19:19 +00:00
2024-11-19 04:31:17 +00:00
if (connectionError) {
return pushToast({theme: "error", message: connectionError})
}
const [authError, accessError] = await Promise.all([checkRelayAuth(url), checkRelayAccess(url)])
const error = authError || accessError
if (error) {
pushModal(SpaceAuthError, {url, error})
}
2024-11-07 23:19:19 +00:00
}
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-11-15 22:03:54 +00:00
const sub = subscribe({
relays: [url],
filters: [{kinds: [MEMBERSHIPS]}, {kinds: [DELETE, REACTION], since: now()}],
})
return () => {
sub.close()
}
})
2024-08-16 19:42:00 +00:00
</script>
2024-11-14 20:16:44 +00:00
<SecondaryNav>
<MenuSpace {url} />
</SecondaryNav>
<Page>
<slot />
</Page>