flotilla/src/app/components/SpaceJoin.svelte

64 lines
2 KiB
Svelte
Raw Normal View History

2024-08-09 00:22:17 +00:00
<script lang="ts">
import {goto} from '$app/navigation'
2024-08-14 00:58:26 +00:00
import {append, uniqBy} from '@welshman/lib'
import {GROUPS} from '@welshman/util'
2024-08-09 00:22:17 +00:00
import CardButton from '@lib/components/CardButton.svelte'
2024-08-14 00:58:26 +00:00
import Spinner from '@lib/components/Spinner.svelte'
2024-08-09 23:22:09 +00:00
import Button from "@lib/components/Button.svelte"
2024-08-09 00:22:17 +00:00
import Field from '@lib/components/Field.svelte'
import Icon from '@lib/components/Icon.svelte'
import SpaceCreateFinish from '@app/components/SpaceCreateFinish.svelte'
import {pushModal} from '@app/modal'
2024-08-09 23:22:09 +00:00
import {pushToast} from '@app/toast'
2024-08-14 23:25:36 +00:00
import {GROUP_DELIMITER, splitGroupId, loadRelay, loadGroup} from '@app/state'
import {joinGroup} from '@app/commands'
2024-08-09 00:22:17 +00:00
const back = () => history.back()
const browse = () => goto("/browse", {state: {}})
2024-08-09 23:22:09 +00:00
const join = async () => {
loading = true
try {
2024-08-14 23:25:36 +00:00
await joinGroup(id)
2024-08-09 23:22:09 +00:00
} finally {
loading = false
}
}
2024-08-14 23:25:36 +00:00
let id = ""
2024-08-09 23:22:09 +00:00
let loading = false
$: linkIsValid = Boolean(id.match(/.+\..+'.+/))
2024-08-09 00:22:17 +00:00
</script>
2024-08-09 23:22:09 +00:00
<form class="column gap-4" on:submit|preventDefault={join}>
<div class="py-2">
<h1 class="heading">Join a Space</h1>
<p class="text-center">
Enter an invite link below to join an existing space.
</p>
</div>
2024-08-09 00:22:17 +00:00
<Field>
<p slot="label">Invite Link*</p>
<label class="input input-bordered w-full flex items-center gap-2" slot="input">
<Icon icon="link-round" />
2024-08-09 23:22:09 +00:00
<input bind:value={id} class="grow" type="text" />
2024-08-09 00:22:17 +00:00
</label>
</Field>
<CardButton icon="compass" title="Don't have an invite?" on:click={browse}>
Browse other spaces on the discover page.
</CardButton>
<div class="flex flex-row justify-between items-center gap-4">
2024-08-09 23:22:09 +00:00
<Button class="btn btn-link" on:click={back}>
2024-08-09 00:22:17 +00:00
<Icon icon="alt-arrow-left" />
Go back
2024-08-09 23:22:09 +00:00
</Button>
<Button type="submit" class="btn btn-primary" disabled={!linkIsValid || loading}>
2024-08-14 00:58:26 +00:00
<Spinner {loading}>Join Space</Spinner>
2024-08-09 23:22:09 +00:00
<Icon icon="alt-arrow-right" />
</Button>
2024-08-09 00:22:17 +00:00
</div>
2024-08-09 23:22:09 +00:00
</form>