Wait for thunk errors

This commit is contained in:
Jon Staab
2025-09-05 17:32:01 -07:00
committed by hodlbod
parent 7217d122b5
commit 998c48b1d3
5 changed files with 14 additions and 11 deletions
+2 -2
View File
@@ -14,7 +14,7 @@
} from "@welshman/util"
import type {Filter} from "@welshman/util"
import {makeIntersectionFeed, makeRelayFeed, feedFromFilters} from "@welshman/feeds"
import {pubkey, signer, getThunkError} from "@welshman/app"
import {pubkey, signer, waitForThunkError} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import FieldInline from "@lib/components/FieldInline.svelte"
@@ -145,7 +145,7 @@
await attemptAuth(NOTIFIER_RELAY)
const thunk = await publishAlert(params)
const error = await getThunkError(thunk)
const error = await waitForThunkError(thunk)
if (error) {
return pushToast({
+4 -4
View File
@@ -2,7 +2,7 @@
import {goto} from "$app/navigation"
import {uniqBy, nth} from "@welshman/lib"
import {displayRelayUrl, makeRoomMeta} from "@welshman/util"
import {deriveRelay, getThunkError, createRoom, editRoom, joinRoom} from "@welshman/app"
import {deriveRelay, waitForThunkError, createRoom, editRoom, joinRoom} from "@welshman/app"
import {preventDefault} from "@lib/html"
import Field from "@lib/components/Field.svelte"
import Spinner from "@lib/components/Spinner.svelte"
@@ -24,19 +24,19 @@
const tryCreate = async () => {
room.tags = uniqBy(nth(0), [...room.tags, ["name", name]])
const createMessage = await getThunkError(createRoom(url, room))
const createMessage = await waitForThunkError(createRoom(url, room))
if (createMessage && !createMessage.match(/^duplicate:|already a member/)) {
return pushToast({theme: "error", message: createMessage})
}
const editMessage = await getThunkError(editRoom(url, room))
const editMessage = await waitForThunkError(editRoom(url, room))
if (editMessage) {
return pushToast({theme: "error", message: editMessage})
}
const joinMessage = await getThunkError(joinRoom(url, room))
const joinMessage = await waitForThunkError(joinRoom(url, room))
if (joinMessage && !joinMessage.includes("already")) {
return pushToast({theme: "error", message: joinMessage})
+3
View File
@@ -7,6 +7,7 @@
import Button from "@lib/components/Button.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import {clearModals} from "@app/util/modal"
import {PROTECTED} from "@app/core/state"
type Props = {
@@ -31,6 +32,8 @@
// Don't publish anywhere yet, wait until they join a space
publishThunk({event, relays: []})
clearModals()
}
</script>
+2 -2
View File
@@ -65,7 +65,7 @@ import {
dropSession,
tagEventForComment,
tagEventForQuote,
getThunkError,
waitForThunkError,
} from "@welshman/app"
import type {SettingsValues} from "@app/core/state"
import {
@@ -249,7 +249,7 @@ export const checkRelayAccess = async (url: string, claim = "") => {
await attemptAuth(url)
const thunk = publishJoinRequest({url, claim})
const error = await getThunkError(thunk)
const error = await waitForThunkError(thunk)
if (error) {
const message =
@@ -15,7 +15,7 @@
ROOM_ADD_USER,
ROOM_REMOVE_USER,
} from "@welshman/util"
import {pubkey, publishThunk, getThunkError, joinRoom, leaveRoom} from "@welshman/app"
import {pubkey, publishThunk, waitForThunkError, joinRoom, leaveRoom} from "@welshman/app"
import {slide, fade, fly} from "@lib/transition"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
@@ -69,7 +69,7 @@
joining = true
try {
const message = await getThunkError(joinRoom(url, makeRoomMeta({id: room})))
const message = await waitForThunkError(joinRoom(url, makeRoomMeta({id: room})))
if (message && !message.startsWith("duplicate:")) {
return pushToast({theme: "error", message})
@@ -85,7 +85,7 @@
const leave = async () => {
leaving = true
try {
const message = await getThunkError(leaveRoom(url, makeRoomMeta({id: room})))
const message = await waitForThunkError(leaveRoom(url, makeRoomMeta({id: room})))
if (message && !message.startsWith("duplicate:")) {
pushToast({theme: "error", message})