flotilla/src/app/components/ThreadBoardItem.svelte

46 lines
1.5 KiB
Svelte
Raw Normal View History

<script lang="ts">
import {formatTimestamp, max} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
import {COMMENT, getTagValue} from "@welshman/util"
2026-06-24 18:19:13 +00:00
import {goto} from "$app/navigation"
import ProfileCircle from "@app/components/ProfileCircle.svelte"
import ProfileName from "@app/components/ProfileName.svelte"
import {deriveEventsForUrl} from "@app/repository"
import {makeThreadPath} from "@app/routes"
type Props = {
url: string
event: TrustedEvent
}
const {url, event}: Props = $props()
const filters = [{kinds: [COMMENT], "#E": [event.id]}]
const replies = deriveEventsForUrl(url, filters)
const replyCount = $derived($replies.length)
const lastActive = $derived(max([...$replies, event].map(e => e.created_at)))
const title = getTagValue("title", event.tags)
2026-06-24 18:19:13 +00:00
const path = makeThreadPath(url, event.id)
const goToThread = () => goto(path)
</script>
<tr
class="cursor-pointer transition-colors hover:bg-surface-less text-sm border-b border-solid border-line"
onclick={goToThread}>
2026-07-02 21:22:55 +00:00
<td class="px-4 py-3 align-top truncate">
{title || "Untitled thread"}
2026-06-24 18:09:44 +00:00
</td>
<td class="px-4 py-3 align-middle flex items-center gap-2">
<ProfileCircle pubkey={event.pubkey} {url} size={5} />
2026-07-02 21:22:55 +00:00
<span class="truncate min-w-0">
<ProfileName pubkey={event.pubkey} {url} />
</span>
2026-06-24 18:09:44 +00:00
</td>
<td class="px-4 py-3 align-middle text-right">
{replyCount}
2026-06-24 18:09:44 +00:00
</td>
2026-06-24 18:19:13 +00:00
<td class="whitespace-nowrap px-4 py-2 align-middle text-right">
{formatTimestamp(lastActive)}
2026-06-24 18:09:44 +00:00
</td>
</tr>