2024-08-09 00:22:17 +00:00
|
|
|
<script lang="ts">
|
2026-01-30 16:41:58 +00:00
|
|
|
import {onMount} from "svelte"
|
2026-07-20 23:35:24 +00:00
|
|
|
import {maybe} from "@welshman/lib"
|
2025-02-04 03:28:29 +00:00
|
|
|
import {preventDefault} from "@lib/html"
|
2025-09-10 22:26:39 +00:00
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
2024-08-16 17:50:38 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2026-01-30 16:41:58 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2026-01-30 22:14:12 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2024-10-10 21:33:50 +00:00
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
2026-01-30 16:41:58 +00:00
|
|
|
import RelaySummary from "@app/components/RelaySummary.svelte"
|
|
|
|
|
import SpaceAccessRequest from "@app/components/SpaceAccessRequest.svelte"
|
2026-07-04 00:17:57 +00:00
|
|
|
import SpaceJoinNotifications from "@app/components/SpaceJoinNotifications.svelte"
|
|
|
|
|
import SpaceJoinStatus from "@app/components/SpaceJoinStatus.svelte"
|
2026-07-20 23:35:24 +00:00
|
|
|
import {Access} from "@app/access"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
|
|
|
|
import {pushToast} from "@app/toast"
|
2026-06-16 22:04:39 +00:00
|
|
|
import {goToSpace} from "@app/routes"
|
2026-01-30 16:41:58 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url}: Props = $props()
|
2024-08-09 00:22:17 +00:00
|
|
|
|
2026-07-20 23:35:24 +00:00
|
|
|
const access = new Access(url)
|
|
|
|
|
|
2024-08-16 19:42:00 +00:00
|
|
|
const back = () => history.back()
|
2024-08-15 19:08:07 +00:00
|
|
|
|
2024-08-09 23:22:09 +00:00
|
|
|
const join = async () => {
|
2026-01-30 16:41:58 +00:00
|
|
|
if (error) {
|
|
|
|
|
return pushModal(SpaceAccessRequest, {url, callback: back})
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 23:22:09 +00:00
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2026-07-20 23:35:24 +00:00
|
|
|
await access.completeJoin(notifications)
|
2025-12-18 02:43:13 +00:00
|
|
|
|
2026-01-30 16:41:58 +00:00
|
|
|
pushToast({message: "Welcome to the space!"})
|
2026-07-06 20:25:20 +00:00
|
|
|
await goToSpace(url)
|
2024-10-11 20:02:48 +00:00
|
|
|
} catch (e) {
|
2026-01-30 16:41:58 +00:00
|
|
|
console.error("Failed to join space:", e)
|
|
|
|
|
pushToast({theme: "error", message: "Failed to join space. Please try again."})
|
|
|
|
|
} finally {
|
2024-08-09 23:22:09 +00:00
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
let error = $state(maybe<string>())
|
2026-01-30 16:41:58 +00:00
|
|
|
let loading = $state(true)
|
|
|
|
|
let notifications = $state(true)
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
2026-07-20 23:35:24 +00:00
|
|
|
error = await access.attempt()
|
2026-01-30 16:41:58 +00:00
|
|
|
loading = false
|
|
|
|
|
})
|
2024-08-09 00:22:17 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-01-30 22:14:12 +00:00
|
|
|
<Modal tag="form" onsubmit={preventDefault(join)}>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<RelaySummary {url} />
|
2026-07-04 00:17:57 +00:00
|
|
|
<SpaceJoinNotifications bind:notifications />
|
2026-07-06 18:35:42 +00:00
|
|
|
{#if error}
|
|
|
|
|
<SpaceJoinStatus {url} {error} />
|
|
|
|
|
{/if}
|
2026-01-30 22:14:12 +00:00
|
|
|
</ModalBody>
|
2024-10-10 21:33:50 +00:00
|
|
|
<ModalFooter>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-link" onclick={back} disabled={loading}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
2024-08-09 00:22:17 +00:00
|
|
|
Go back
|
2024-08-09 23:22:09 +00:00
|
|
|
</Button>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button type="submit" class="button button-primary" disabled={loading}>
|
2026-01-30 22:14:12 +00:00
|
|
|
<Spinner {loading}>
|
2026-01-30 16:41:58 +00:00
|
|
|
{error ? "Request Access" : "Join Space"}
|
|
|
|
|
</Spinner>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={AltArrowRight} />
|
2024-08-09 23:22:09 +00:00
|
|
|
</Button>
|
2024-10-10 21:33:50 +00:00
|
|
|
</ModalFooter>
|
2026-01-30 22:14:12 +00:00
|
|
|
</Modal>
|