Validate space connection before joining

This commit is contained in:
Jon Staab
2024-10-10 14:33:50 -07:00
parent 821a6a095f
commit 0d394bbc3b
18 changed files with 204 additions and 88 deletions
+11 -13
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import {goto} from "$app/navigation"
import {tryCatch} from "@welshman/lib"
import {ctx, tryCatch} from "@welshman/lib"
import {isRelayUrl, normalizeRelayUrl} from "@welshman/util"
import {loadRelay} from "@welshman/app"
import CardButton from "@lib/components/CardButton.svelte"
@@ -9,26 +9,24 @@
import Field from "@lib/components/Field.svelte"
import Icon from "@lib/components/Icon.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalFooter from '@lib/components/ModalFooter.svelte'
import InfoRelay from "@app/components/InfoRelay.svelte"
import {pushToast} from "@app/toast"
import {pushModal} from "@app/modal"
import {addSpaceMembership} from "@app/commands"
import {addSpaceMembership, attemptRelayAccess} from "@app/commands"
import {makeSpacePath} from "@app/routes"
const back = () => history.back()
const browse = () => goto("/discover")
const joinRelay = async (url: string) => {
url = normalizeRelayUrl(url)
const joinRelay = async (invite: string) => {
const [raw, claim] = invite.split("'")
const url = normalizeRelayUrl(raw)
const error = await attemptRelayAccess(url, claim)
const relay = await loadRelay(url)
if (!relay?.profile) {
return pushToast({
theme: "error",
message: "Sorry, we weren't able to find that relay.",
})
if (error) {
return pushToast({theme: "error", message: error})
}
await addSpaceMembership(url)
@@ -78,7 +76,7 @@
<div slot="info">Browse other spaces on the discover page.</div>
</CardButton>
</Button>
<div class="flex flex-row items-center justify-between gap-4">
<ModalFooter>
<Button class="btn btn-link" on:click={back}>
<Icon icon="alt-arrow-left" />
Go back
@@ -87,5 +85,5 @@
<Spinner {loading}>Join Space</Spinner>
<Icon icon="alt-arrow-right" />
</Button>
</div>
</ModalFooter>
</form>