2024-08-16 19:42:00 +00:00
|
|
|
<script lang="ts">
|
2026-02-19 19:08:06 +00:00
|
|
|
import {debounce} from "throttle-debounce"
|
2026-07-20 23:35:24 +00:00
|
|
|
import {maybe} from "@welshman/lib"
|
|
|
|
|
import {goto} from "$app/navigation"
|
2025-02-04 03:28:29 +00:00
|
|
|
import {preventDefault} from "@lib/html"
|
2025-09-06 00:20:12 +00:00
|
|
|
import {slideAndFade} from "@lib/transition"
|
2024-08-16 19:42:00 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Field from "@lib/components/Field.svelte"
|
2025-09-10 22:26:39 +00:00
|
|
|
import LinkRound from "@assets/icons/link-round.svg?dataurl"
|
|
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
2024-08-16 19:42:00 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2026-02-19 19:08:06 +00:00
|
|
|
import Scanner from "@lib/components/Scanner.svelte"
|
|
|
|
|
import QrCode from "@assets/icons/qr-code.svg?dataurl"
|
2026-01-30 22:14:12 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2024-10-09 23:11:23 +00:00
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
2026-02-02 18:09:14 +00:00
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
2024-10-11 00:15:20 +00:00
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
2025-09-06 00:20:12 +00:00
|
|
|
import RelaySummary from "@app/components/RelaySummary.svelte"
|
2026-07-04 00:17:57 +00:00
|
|
|
import SpaceJoinNotifications from "@app/components/SpaceJoinNotifications.svelte"
|
|
|
|
|
import SpaceJoinStatus from "@app/components/SpaceJoinStatus.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2026-07-20 23:35:24 +00:00
|
|
|
import {goToSpace, makeRoomPath} from "@app/routes"
|
|
|
|
|
import {Access, parseInviteLink} from "@app/access"
|
2024-08-16 19:42:00 +00:00
|
|
|
|
2025-09-06 00:20:12 +00:00
|
|
|
type Props = {
|
|
|
|
|
invite: string
|
2026-01-30 22:14:12 +00:00
|
|
|
back?: () => void
|
2026-07-04 00:01:37 +00:00
|
|
|
hideHeader?: boolean
|
2025-09-06 00:20:12 +00:00
|
|
|
}
|
2025-05-20 16:35:33 +00:00
|
|
|
|
2026-07-04 00:01:37 +00:00
|
|
|
let {invite = "", back = () => history.back(), hideHeader}: Props = $props()
|
2025-05-20 16:35:33 +00:00
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
const toggleScanner = () => {
|
|
|
|
|
showScanner = !showScanner
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onScan = debounce(1000, async (data: string) => {
|
|
|
|
|
showScanner = false
|
|
|
|
|
invite = data
|
|
|
|
|
})
|
|
|
|
|
|
2025-09-06 00:20:12 +00:00
|
|
|
const joinRelay = async () => {
|
2026-07-20 23:35:24 +00:00
|
|
|
const data = inviteData!
|
|
|
|
|
const access = new Access(data.url)
|
2025-05-20 16:35:33 +00:00
|
|
|
|
2026-07-20 23:35:24 +00:00
|
|
|
error = await access.acceptInvite(data, notifications)
|
2024-09-11 17:48:34 +00:00
|
|
|
|
2026-07-20 23:35:24 +00:00
|
|
|
if (error) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-02-19 19:08:06 +00:00
|
|
|
|
2026-07-20 23:35:24 +00:00
|
|
|
if (data.h) {
|
|
|
|
|
const path = makeRoomPath(data.url, data.h)
|
|
|
|
|
const qp = data.code ? `?code=${encodeURIComponent(data.code)}` : ""
|
2026-07-06 20:25:20 +00:00
|
|
|
|
2026-07-20 23:35:24 +00:00
|
|
|
pushToast({message: "Welcome to the room!"})
|
|
|
|
|
await goto(path + qp)
|
|
|
|
|
return
|
2026-02-19 19:08:06 +00:00
|
|
|
}
|
2026-07-20 23:35:24 +00:00
|
|
|
|
|
|
|
|
pushToast({message: "Welcome to the space!"})
|
|
|
|
|
await goToSpace(data.url)
|
2024-08-16 19:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const join = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2025-05-20 16:35:33 +00:00
|
|
|
await joinRelay()
|
2024-08-16 19:42:00 +00:00
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
let error = $state(maybe<string>())
|
2025-02-04 00:37:14 +00:00
|
|
|
let loading = $state(false)
|
2026-02-19 19:08:06 +00:00
|
|
|
let showScanner = $state(false)
|
|
|
|
|
let notifications = $state(true)
|
2024-08-16 19:42:00 +00:00
|
|
|
|
2025-11-05 00:39:34 +00:00
|
|
|
const inviteData = $derived(parseInviteLink(invite))
|
2026-07-20 23:35:24 +00:00
|
|
|
const isRoomInvite = $derived(Boolean(inviteData?.h))
|
2024-08-16 19:42:00 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-01-30 22:14:12 +00:00
|
|
|
<Modal tag="form" onsubmit={preventDefault(join)}>
|
|
|
|
|
<ModalBody>
|
2026-07-04 00:01:37 +00:00
|
|
|
{#if !hideHeader}
|
|
|
|
|
<ModalHeader>
|
2026-07-20 23:35:24 +00:00
|
|
|
<ModalTitle>{isRoomInvite ? "Join a Room" : "Join a Space"}</ModalTitle>
|
|
|
|
|
<ModalSubtitle>
|
|
|
|
|
{#if isRoomInvite}
|
|
|
|
|
Enter a room invite link below to join an existing room.
|
|
|
|
|
{:else}
|
|
|
|
|
Enter a relay URL or invite link below to join an existing space.
|
|
|
|
|
{/if}
|
|
|
|
|
</ModalSubtitle>
|
2026-07-04 00:01:37 +00:00
|
|
|
</ModalHeader>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Invite Link*</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<label class="input flex w-full items-center gap-2">
|
|
|
|
|
<Icon icon={LinkRound} />
|
|
|
|
|
<input bind:value={invite} class="grow" type="text" />
|
|
|
|
|
<Button onclick={toggleScanner} class="flex items-center justify-center">
|
|
|
|
|
<Icon icon={QrCode} />
|
|
|
|
|
</Button>
|
|
|
|
|
</label>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
{#if showScanner}
|
|
|
|
|
<Scanner onscan={onScan} />
|
|
|
|
|
{/if}
|
2026-02-19 19:08:06 +00:00
|
|
|
{/if}
|
2025-09-06 00:20:12 +00:00
|
|
|
{#if inviteData}
|
2026-01-30 22:14:12 +00:00
|
|
|
<div class="-my-4">
|
|
|
|
|
<div transition:slideAndFade class="flex flex-col gap-4 py-4">
|
2026-06-24 20:56:53 +00:00
|
|
|
<div class="card flex flex-col gap-4">
|
2026-01-30 22:14:12 +00:00
|
|
|
<p class="opacity-75">You're about to join:</p>
|
|
|
|
|
<RelaySummary url={inviteData.url} />
|
2026-07-04 00:17:57 +00:00
|
|
|
<SpaceJoinNotifications bind:notifications />
|
2026-07-04 00:24:14 +00:00
|
|
|
{#if error}
|
|
|
|
|
<SpaceJoinStatus url={inviteData.url} {error} />
|
|
|
|
|
{/if}
|
2026-01-30 22:14:12 +00:00
|
|
|
</div>
|
2025-09-06 00:20:12 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/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}>
|
2026-01-30 22:14:12 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
|
|
|
|
Go back
|
|
|
|
|
</Button>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button type="submit" class="button button-primary" disabled={!inviteData || loading}>
|
2026-07-20 23:35:24 +00:00
|
|
|
<Spinner {loading}>{isRoomInvite ? "Join Room" : "Join Space"}</Spinner>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={AltArrowRight} />
|
2024-08-16 19:42:00 +00:00
|
|
|
</Button>
|
2024-10-10 21:33:50 +00:00
|
|
|
</ModalFooter>
|
2026-01-30 22:14:12 +00:00
|
|
|
</Modal>
|