flotilla/src/app/components/ClassifiedItem.svelte

62 lines
2.1 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-02-04 01:09:30 +00:00
import {getTag, getAddress, getTagValue, getTagValues} from "@welshman/util"
2026-02-03 19:00:13 +00:00
import Link from "@lib/components/Link.svelte"
2026-02-04 01:09:30 +00:00
import CurrencySymbol from "@lib/components/CurrencySymbol.svelte"
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 RoomLink from "@app/components/RoomLink.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
}
const {url, event}: Props = $props()
const title = getTagValue("title", event.tags)
const h = getTagValue("h", event.tags)
2026-03-30 21:29:24 +00:00
const images = new Set(getTagValues("image", event.tags))
2026-02-04 01:09:30 +00:00
const [_, price = 0, currency = "SAT"] = getTag("price", event.tags) || []
2026-02-03 19:00:13 +00:00
</script>
<Link
class="cv flex flex-col gap-2 card card-interactive w-full"
href={makeClassifiedPath(url, getAddress(event))}>
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} —
<CurrencySymbol code={currency} />{price}
</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} />
</div>
</Link>