flotilla/src/app/components/EventActivity.svelte

34 lines
1.2 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"
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-07-28 16:16:26 +00:00
import {deriveEvents} from "@app/repository"
import {network} from "@app/core"
import {deriveChecked} from "@app/notifications"
2025-02-06 17:53:50 +00:00
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]}]
2026-07-28 16:16:26 +00:00
const replies = deriveEvents(filters)
2025-02-06 17:53:50 +00:00
const lastActive = $derived(max([...$replies, event].map(e => e.created_at)))
onMount(() => {
2026-07-28 16:16:26 +00:00
$network.load({relays: [url], filters})
2025-02-06 17:53:50 +00:00
})
</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>