flotilla/src/app/components/ClassifiedItem.svelte

69 lines
2.4 KiB
Svelte
Raw Normal View History

2026-02-03 19:00:13 +00:00
<script lang="ts">
import {formatTimestamp} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
2026-07-28 16:16:26 +00:00
import {getAddress} from "@welshman/util"
import {Classified} from "@welshman/domain"
2026-02-03 19:00:13 +00:00
import Link from "@lib/components/Link.svelte"
import Cv from "@lib/components/Cv.svelte"
2026-02-04 01:09:30 +00:00
import CurrencySymbol from "@lib/components/CurrencySymbol.svelte"
2026-07-28 16:16:26 +00:00
import {reader} from "@app/core"
2026-02-03 22:18:58 +00:00
import ContentLinkBlock from "@app/components/ContentLinkBlock.svelte"
2026-02-03 19:00:13 +00:00
import Content from "@app/components/Content.svelte"
import ProfileLink from "@app/components/ProfileLink.svelte"
import ClassifiedActions from "@app/components/ClassifiedActions.svelte"
import type {FeedContext} from "@app/feeds"
2026-02-03 19:00:13 +00:00
import RoomLink from "@app/components/RoomLink.svelte"
import UnreadDot from "@app/components/UnreadDot.svelte"
2026-06-08 21:14:40 +00:00
import {makeClassifiedPath} from "@app/routes"
2026-02-03 19:00:13 +00:00
type Props = {
url: string
event: TrustedEvent
context: FeedContext
2026-02-03 19:00:13 +00:00
}
const {url, event, context}: Props = $props()
2026-02-03 19:00:13 +00:00
const path = $derived(makeClassifiedPath(url, getAddress(event)))
2026-08-22 20:12:11 +00:00
const classified = $derived(reader(Classified)(event))
const title = $derived(classified.title())
const h = $derived(classified.room())
const images = $derived(new Set(classified.images()))
const price = $derived(classified.price())
2026-02-03 19:00:13 +00:00
</script>
<Cv tag={Link} class="relative flex flex-col gap-2 card card-interactive w-full" href={path}>
<UnreadDot {path} class="absolute right-3 top-3" />
2026-02-03 19:00:13 +00:00
{#if title}
<div class="flex w-full items-center justify-between gap-2">
2026-02-04 01:09:30 +00:00
<p class="text-xl">
{title} —
2026-07-28 16:16:26 +00:00
<CurrencySymbol code={price?.currency ?? "SAT"} />{price?.amount ?? 0}
2026-02-04 01:09:30 +00:00
</p>
2026-02-03 19:00:13 +00:00
<p class="text-sm opacity-75">
{formatTimestamp(event.created_at)}
</p>
</div>
{:else}
<p class="mb-3 h-0 text-xs opacity-75">
{formatTimestamp(event.created_at)}
</p>
{/if}
<Content {event} {url} expandMode="inline" />
2026-02-03 22:18:58 +00:00
<div class="grid grid-cols-3 sm:grid-cols-5">
{#each images as image (image)}
<ContentLinkBlock {event} value={{url: image}} />
{/each}
</div>
2026-02-03 19:00:13 +00:00
<div class="flex w-full flex-col items-end justify-between gap-2 sm:flex-row">
<span class="whitespace-nowrap py-1 text-sm opacity-75">
Posted by
<ProfileLink pubkey={event.pubkey} {url} />
{#if h}
in <RoomLink {url} {h} />
{/if}
</span>
<ClassifiedActions showActivity {url} {event} {context} />
2026-02-03 19:00:13 +00:00
</div>
</Cv>