flotilla/src/app/components/ThunkToast.svelte

39 lines
889 B
Svelte
Raw Normal View History

<script lang="ts">
2026-07-28 16:16:26 +00:00
import type {BaseThunk} from "@welshman/app"
import {PublishStatus} from "@welshman/net"
import ThunkPending from "@app/components/ThunkPending.svelte"
2026-06-08 21:14:40 +00:00
import type {Toast} from "@app/toast"
import {popToast} from "@app/toast"
type Props = {
toast: Toast
2026-07-28 16:16:26 +00:00
thunk: BaseThunk
}
const {toast, ...props}: Props = $props()
const id = toast.id
const thunk = props.thunk
const {Aborted, Timeout, Failure} = PublishStatus
2026-07-28 16:16:26 +00:00
const isFailure = $derived($thunk.hasStatus([Aborted, Timeout, Failure]))
const isComplete = $derived($thunk.isComplete())
$effect(() => {
if (isFailure) {
popToast(id)
}
})
$effect(() => {
if (isComplete) {
setTimeout(() => popToast(id), 2000)
}
})
</script>
{#if !isComplete}
<ThunkPending {thunk} />
{:else if !isFailure}
<p class="text-xs opacity-75">Message sent!</p>
{/if}