2025-02-06 17:53:50 +00:00
|
|
|
<script lang="ts">
|
2026-08-29 16:48:04 +00:00
|
|
|
import {derived} from "svelte/store"
|
2026-09-03 20:13:21 +00:00
|
|
|
import {filter, max, spec, formatTimestampRelative} from "@welshman/lib"
|
2026-08-29 16:48:04 +00:00
|
|
|
import {COMMENT} from "@welshman/util"
|
2025-02-06 17:53:50 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2025-09-10 22:26:39 +00:00
|
|
|
import Reply from "@assets/icons/reply-2.svg?dataurl"
|
2025-02-06 17:53:50 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2026-08-29 16:48:04 +00:00
|
|
|
import type {FeedContext} from "@app/feeds"
|
2025-02-06 17:53:50 +00:00
|
|
|
|
2026-08-18 21:18:10 +00:00
|
|
|
// hideLastActive: redundant next to a detail page's own comments below.
|
|
|
|
|
const {
|
|
|
|
|
event,
|
|
|
|
|
context,
|
|
|
|
|
size = "xs",
|
|
|
|
|
hideLastActive,
|
|
|
|
|
}: {
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
context: FeedContext
|
|
|
|
|
size?: "xs" | "sm"
|
|
|
|
|
hideLastActive?: boolean
|
|
|
|
|
} = $props()
|
|
|
|
|
|
|
|
|
|
const buttonClass = `button button-neutral button-${size} rounded-full`
|
2025-02-06 17:53:50 +00:00
|
|
|
|
2026-08-29 16:48:04 +00:00
|
|
|
const related = context.related(event)
|
|
|
|
|
const replies = derived(related, $related => filter(spec({kind: COMMENT}), $related))
|
2025-02-06 17:53:50 +00:00
|
|
|
const lastActive = $derived(max([...$replies, event].map(e => e.created_at)))
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-08-18 21:18:10 +00:00
|
|
|
<div class="flex-inline {buttonClass} gap-1">
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={Reply} />
|
2025-02-06 17:53:50 +00:00
|
|
|
<span>{$replies.length} {$replies.length === 1 ? "reply" : "replies"}</span>
|
|
|
|
|
</div>
|
2026-08-18 21:18:10 +00:00
|
|
|
{#if !hideLastActive}
|
2026-09-03 20:13:21 +00:00
|
|
|
<div class={buttonClass}>
|
2026-08-18 21:18:10 +00:00
|
|
|
Active {formatTimestampRelative(lastActive)}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|