flotilla/src/app/components/ThunkStatusDetail.svelte

71 lines
2.4 KiB
Svelte
Raw Normal View History

2024-10-17 18:56:13 +00:00
<script lang="ts">
import {stopPropagation} from "svelte/legacy"
2024-10-17 23:03:50 +00:00
import {PublishStatus} from "@welshman/net"
import {displayRelayUrl} from "@welshman/util"
2026-07-28 16:16:26 +00:00
import {BaseThunk} from "@welshman/app"
import CheckCircle from "@assets/icons/check-circle.svg?dataurl"
import Danger from "@assets/icons/danger-triangle.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
2024-10-17 23:03:50 +00:00
import Button from "@lib/components/Button.svelte"
2026-02-16 16:16:03 +00:00
import {addPeriod} from "@lib/util"
2024-10-17 18:56:13 +00:00
2025-02-04 00:37:14 +00:00
interface Props {
2026-07-28 16:16:26 +00:00
thunk: BaseThunk
retry: (url: string) => void
2025-02-04 00:37:14 +00:00
}
const {thunk, retry}: Props = $props()
2024-10-17 18:56:13 +00:00
2026-07-28 16:16:26 +00:00
const successUrls = $derived($thunk.getUrlsWithStatus(PublishStatus.Success))
const failedUrls = $derived($thunk.getFailedUrls())
const total = $derived(successUrls.length + failedUrls.length)
const isPartial = $derived(successUrls.length > 0 && failedUrls.length > 0)
const title = $derived(
isPartial ? `Partial delivery ${successUrls.length}/${total} relays` : "Failed to send!",
)
const relayMessage = (status: PublishStatus | undefined, detail: string | undefined) => {
if (status === PublishStatus.Timeout) {
return "request timed out"
2024-10-17 19:29:28 +00:00
}
2026-08-21 15:31:53 +00:00
if (detail) {
return detail
}
return "no details received"
}
2024-10-17 18:56:13 +00:00
</script>
<div class="card flex min-w-72 max-w-sm flex-col gap-3 px-4 py-3">
<span class="flex items-center gap-2 text-sm font-medium">
<Icon icon={Danger} class="text-error" size={4} />
{title}
</span>
<div class="divider my-0"></div>
<div class="flex flex-col gap-3">
{#each successUrls as url (url)}
<div class="flex items-start gap-2 text-sm">
<Icon icon={CheckCircle} class="mt-0.5 shrink-0 text-success" size={4} />
<span>{displayRelayUrl(url)}</span>
</div>
{/each}
{#each failedUrls as url (url)}
{@const {detail, status} = $thunk.results[url] || {}}
<div class="grid grid-cols-[1rem_1fr_auto] items-start gap-x-3 gap-y-1 text-sm">
<Icon icon={Danger} class="mt-0.5 text-error" size={4} />
<div class="min-w-0">
<p class="break-all">{displayRelayUrl(url)}</p>
<p class="text-xs opacity-60">{addPeriod(relayMessage(status, detail))}</p>
</div>
<Button
class="button button-link shrink-0 px-1"
onclick={stopPropagation(() => retry(url))}>
Retry
</Button>
</div>
{/each}
</div>
2024-10-17 18:56:13 +00:00
</div>