flotilla/src/app/components/EventActivity.svelte

35 lines
1.3 KiB
Svelte
Raw Normal View History

2025-02-06 17:53:50 +00:00
<script lang="ts">
import {onMount} from "svelte"
import {max, gt, formatTimestampRelative} from "@welshman/lib"
2025-02-06 17:53:50 +00:00
import {COMMENT} from "@welshman/util"
2025-04-09 22:32:18 +00:00
import {load} from "@welshman/net"
2025-11-20 23:54:06 +00:00
import {deriveArray, deriveEventsById} from "@welshman/store"
2025-02-06 17:53:50 +00:00
import type {TrustedEvent} from "@welshman/util"
2025-05-05 17:11:02 +00:00
import {repository} from "@welshman/app"
import {deriveChecked} from "@app/util/notifications"
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"
const {url, path, event}: {url: string; path: string; event: TrustedEvent} = $props()
const checked = deriveChecked(path)
2025-02-06 17:53:50 +00:00
const filters = [{kinds: [COMMENT], "#E": [event.id]}]
2025-11-20 23:54:06 +00:00
const replies = deriveArray(deriveEventsById({repository, filters}))
2025-02-06 17:53:50 +00:00
const lastActive = $derived(max([...$replies, event].map(e => e.created_at)))
onMount(() => {
load({relays: [url], filters})
})
</script>
<div class="flex-inline btn btn-neutral btn-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>
2026-02-18 18:22:23 +00:00
<div class="btn btn-neutral btn-xs relative rounded-full">
{#if gt(lastActive, $checked)}
2025-02-06 17:53:50 +00:00
<div class="h-2 w-2 rounded-full bg-primary"></div>
{/if}
Active {formatTimestampRelative(lastActive)}
</div>