Refactor confirm to avoid passing closures
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import {goto} from "$app/navigation"
|
||||
import {ctx, tryCatch} from "@welshman/lib"
|
||||
import {isRelayUrl, normalizeRelayUrl} from "@welshman/util"
|
||||
import {preventDefault} from "@lib/html"
|
||||
@@ -7,27 +6,16 @@
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import Field from "@lib/components/Field.svelte"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Confirm from "@lib/components/Confirm.svelte"
|
||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||
import InfoRelay from "@app/components/InfoRelay.svelte"
|
||||
import SpaceJoinConfirm, {confirmSpaceJoin} from "@app/components/SpaceJoinConfirm.svelte"
|
||||
import {pushToast} from "@app/toast"
|
||||
import {pushModal} from "@app/modal"
|
||||
import {addSpaceMembership, attemptRelayAccess} from "@app/commands"
|
||||
import {makeSpacePath} from "@app/routes"
|
||||
import {attemptRelayAccess} from "@app/commands"
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
const confirm = async (url: string) => {
|
||||
await addSpaceMembership(url)
|
||||
|
||||
goto(makeSpacePath(url), {replaceState: true})
|
||||
|
||||
pushToast({
|
||||
message: "Welcome to the space!",
|
||||
})
|
||||
}
|
||||
|
||||
const joinRelay = async (invite: string) => {
|
||||
const [raw, claim] = invite.split("|")
|
||||
const url = normalizeRelayUrl(raw)
|
||||
@@ -40,13 +28,9 @@
|
||||
const connection = ctx.net.pool.get(url)
|
||||
|
||||
if (connection.stats.lastAuth === 0) {
|
||||
pushModal(Confirm, {
|
||||
confirm: () => confirm(url),
|
||||
message: `This space does not appear to limit who can post to it. This can result
|
||||
in a large amount of spam or other objectionable content. Continue?`,
|
||||
})
|
||||
pushModal(SpaceJoinConfirm, {url}, {replaceState: true})
|
||||
} else {
|
||||
await confirm(url)
|
||||
await confirmSpaceJoin(url)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user