2025-08-19 21:03:04 +00:00
|
|
|
<script lang="ts">
|
2026-07-28 16:16:26 +00:00
|
|
|
import type {BaseThunk} from "@welshman/app"
|
2025-08-19 21:03:04 +00:00
|
|
|
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"
|
2025-08-19 21:03:04 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
toast: Toast
|
2026-07-28 16:16:26 +00:00
|
|
|
thunk: BaseThunk
|
2025-08-19 21:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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())
|
2025-08-19 21:03:04 +00:00
|
|
|
|
|
|
|
|
$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}
|