flotilla/src/app/components/EventActivity.svelte

29 lines
1.2 KiB
Svelte
Raw Normal View History

2025-02-06 17:53:50 +00:00
<script lang="ts">
import {derived} from "svelte/store"
import {filter, max, gt, spec, formatTimestampRelative} from "@welshman/lib"
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"
import type {FeedContext} from "@app/feeds"
2026-07-28 16:16:26 +00:00
import {deriveChecked} from "@app/notifications"
2025-02-06 17:53:50 +00:00
const {path, event, context}: {path: string; event: TrustedEvent; context: FeedContext} = $props()
2025-02-06 17:53:50 +00:00
const checked = deriveChecked(path)
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>
<div class="flex-inline button button-neutral button-xs gap-1 rounded-full">
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>
<div class="button button-neutral button-xs relative rounded-full">
{#if gt(lastActive, $checked)}
<div class="h-2 w-2 rounded-full bg-primary text-primary-content"></div>
2025-02-06 17:53:50 +00:00
{/if}
Active {formatTimestampRelative(lastActive)}
</div>