flotilla/src/app/components/ThunkFailure.svelte

62 lines
1.8 KiB
Svelte
Raw Normal View History

<script lang="ts">
import {stopPropagation} from "svelte/legacy"
import {noop} from "@welshman/lib"
2026-07-28 16:16:26 +00:00
import type {BaseThunk} from "@welshman/app"
2025-09-10 22:26:39 +00:00
import Danger from "@assets/icons/danger-triangle.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
import Tippy from "@lib/components/Tippy.svelte"
import ThunkToast from "@app/components/ThunkToast.svelte"
import ThunkStatusDetail from "@app/components/ThunkStatusDetail.svelte"
2026-07-28 16:16:26 +00:00
import {thunks} from "@app/core"
2026-06-08 21:14:40 +00:00
import {pushToast} from "@app/toast"
2026-07-28 16:16:26 +00:00
type Props = {
thunk: BaseThunk
showToastOnRetry?: boolean
class?: string
}
const {thunk, showToastOnRetry, ...restProps}: Props = $props()
2026-07-28 16:16:26 +00:00
const showFailure = $derived($thunk.isComplete() && $thunk.getFailedUrls().length > 0)
const retry = (url: string) => {
2026-07-28 16:16:26 +00:00
for (const child of $thunks.flatten([thunk])) {
if (child.options.relays.includes(url)) {
const retried = $thunks.publish({...child.options, relays: [url]})
if (showToastOnRetry) {
pushToast({
timeout: 30_000,
children: {
component: ThunkToast,
props: {thunk: retried},
},
})
}
return
}
}
}
</script>
{#if showFailure}
<button
class="flex w-full justify-end px-1 text-xs {restProps.class}"
onclick={stopPropagation(noop)}>
<Tippy
class="flex items-center"
component={ThunkStatusDetail}
props={{thunk, retry}}
params={{interactive: true, maxWidth: "none"}}>
{#snippet children()}
<span class="flex cursor-pointer items-center gap-1 opacity-75">
<Icon icon={Danger} class="text-error" size={3} />
<span>Failed to send!</span>
</span>
{/snippet}
</Tippy>
</button>
{/if}