2024-10-16 22:57:18 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {displayRelayUrl} from "@welshman/util"
|
|
|
|
|
import {PublishStatus} from "@welshman/net"
|
2024-10-17 18:27:17 +00:00
|
|
|
import type {Thunk, MergedThunk} from "@welshman/app"
|
2024-10-16 22:57:18 +00:00
|
|
|
import Icon from '@lib/components/Icon.svelte'
|
|
|
|
|
import Button from '@lib/components/Button.svelte'
|
|
|
|
|
|
2024-10-17 18:27:17 +00:00
|
|
|
export let thunk: Thunk | MergedThunk
|
2024-10-16 22:57:18 +00:00
|
|
|
|
|
|
|
|
const {status} = thunk
|
|
|
|
|
const {Pending, Success, Failure, Timeout} = PublishStatus
|
|
|
|
|
|
2024-10-17 18:27:17 +00:00
|
|
|
const abort = () => thunk.controller.abort()
|
2024-10-16 22:57:18 +00:00
|
|
|
|
|
|
|
|
$: ps = Object.values($status)
|
2024-10-17 18:27:17 +00:00
|
|
|
$: canCancel = ps.length === 0
|
2024-10-16 22:57:18 +00:00
|
|
|
$: isPending = ps.some(s => s.status === Pending)
|
|
|
|
|
$: isSuccess = ps.some(s => s.status === Success)
|
2024-10-17 18:27:17 +00:00
|
|
|
$: isFailure = !canCancel && ps.every(s => [Failure, Timeout].includes(s.status))
|
2024-10-17 15:53:03 +00:00
|
|
|
$: failure = Object.entries($status).find(([url, s]) => [Failure, Timeout].includes(s.status))
|
2024-10-16 22:57:18 +00:00
|
|
|
</script>
|
|
|
|
|
|
2024-10-17 18:27:17 +00:00
|
|
|
{#if canCancel || isPending}
|
|
|
|
|
<span class="flex gap-1 mt-2 items-center">
|
2024-10-16 22:57:18 +00:00
|
|
|
<span class="loading loading-spinner mx-1 h-3 w-3 translate-y-px" />
|
|
|
|
|
<span class="opacity-50">Sending...</span>
|
2024-10-17 18:27:17 +00:00
|
|
|
{#if canCancel}
|
|
|
|
|
<Button class="link" on:click={abort}>Cancel</Button>
|
2024-10-16 22:57:18 +00:00
|
|
|
{/if}
|
|
|
|
|
</span>
|
|
|
|
|
{:else if isFailure && failure}
|
2024-10-17 15:53:03 +00:00
|
|
|
{@const [url, {message}] = failure}
|
2024-10-16 22:57:18 +00:00
|
|
|
<span
|
2024-10-17 18:27:17 +00:00
|
|
|
class="flex tooltip cursor-pointer gap-1 mt-2"
|
2024-10-17 15:53:03 +00:00
|
|
|
data-tip="{message} ({displayRelayUrl(url)})">
|
2024-10-16 22:57:18 +00:00
|
|
|
<Icon icon="danger" class="translate-y-px" size={3} />
|
|
|
|
|
<span class="opacity-50">Failed to send!</span>
|
|
|
|
|
</span>
|
|
|
|
|
{/if}
|