flotilla/src/app/components/ArticleItem.svelte

63 lines
2.4 KiB
Svelte
Raw Normal View History

2026-08-17 15:42:14 +00:00
<script lang="ts">
import {formatTimestamp} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
import {getAddress} from "@welshman/util"
import {Article} from "@welshman/domain"
import Link from "@lib/components/Link.svelte"
import Cv from "@lib/components/Cv.svelte"
2026-08-17 15:42:14 +00:00
import Content from "@app/components/Content.svelte"
import ProfileLink from "@app/components/ProfileLink.svelte"
import ArticleActions from "@app/components/ArticleActions.svelte"
import UnreadDot from "@app/components/UnreadDot.svelte"
import type {FeedContext} from "@app/feeds"
2026-08-17 15:42:14 +00:00
import {reader} from "@app/core"
import {makeArticlePath} from "@app/routes"
type Props = {
url: string
event: TrustedEvent
context: FeedContext
2026-08-17 15:42:14 +00:00
}
const {url, event, context}: Props = $props()
2026-08-17 15:42:14 +00:00
const path = $derived(makeArticlePath(url, getAddress(event)))
2026-08-22 20:12:11 +00:00
const article = $derived(reader(Article)(event))
const title = $derived(article.title())
const summary = $derived(article.summary())
const image = $derived(article.image())
2026-08-17 15:42:14 +00:00
</script>
<Cv data-component="ArticleItem" class="relative w-full card card-interactive">
<!-- An overlay rather than a wrapper: the card carries a profile button and the room and action
links, and none of those may sit inside an anchor. -->
<Link class="absolute inset-0 rounded-2xl" href={path} aria-label={title || "Untitled"} />
<UnreadDot {path} class="absolute right-3 top-3" />
<div class="pointer-events-none relative flex flex-col gap-2">
{#if image}
<img src={image} alt="" class="h-40 w-full rounded-2xl object-cover" />
{/if}
<div class="flex w-full items-center justify-between gap-2">
<p class="text-xl">{title || "Untitled"}</p>
<p class="whitespace-nowrap text-sm opacity-75">
{formatTimestamp(article.publishedAt())}
</p>
</div>
<Content
event={{content: summary || event.content, tags: event.tags}}
{url}
expandMode="inline"
minLength={100}
maxLength={300} />
2026-08-31 15:12:54 +00:00
<div class="flex w-full flex-col items-end justify-between gap-2 sm:flex-row">
<span class="pointer-events-auto whitespace-nowrap py-1 text-sm opacity-75">
Written by
<ProfileLink pubkey={event.pubkey} {url} />
</span>
2026-08-31 15:12:54 +00:00
<div class="pointer-events-auto shrink-0">
<ArticleActions showRoom showActivity {url} {event} {context} />
</div>
</div>
2026-08-17 15:42:14 +00:00
</div>
</Cv>