flotilla/src/app/components/NoteCard.svelte

66 lines
2.1 KiB
Svelte
Raw Normal View History

2024-09-24 21:12:38 +00:00
<script lang="ts">
2024-11-21 22:14:46 +00:00
import cx from "classnames"
import type {Snippet} from "svelte"
2025-05-05 17:11:02 +00:00
import {formatTimestamp} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
2025-09-10 22:26:39 +00:00
import Danger from "@assets/icons/danger-triangle.svg?dataurl"
2024-10-17 22:58:18 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
2024-09-24 21:12:38 +00:00
import Profile from "@app/components/Profile.svelte"
2024-11-21 22:14:46 +00:00
import ProfileName from "@app/components/ProfileName.svelte"
2026-06-08 21:14:40 +00:00
import {goToEvent} from "@app/routes"
import {isEventMuted} from "@app/social"
2024-09-24 21:12:38 +00:00
2026-07-28 16:16:26 +00:00
type Props = {
2025-02-04 00:37:14 +00:00
event: TrustedEvent
2026-06-24 20:10:06 +00:00
children?: Snippet
minimal?: boolean
hideProfile?: boolean
2025-04-15 18:03:27 +00:00
url?: string
class?: string
style?: string
2026-07-28 16:16:26 +00:00
}
const {event, children, minimal = false, hideProfile = false, url, ...restProps}: Props = $props()
2024-10-01 23:27:25 +00:00
2024-10-17 22:58:18 +00:00
const ignoreMute = () => {
muted = false
}
2026-07-28 16:16:26 +00:00
const goToNote = () => goToEvent(event)
2026-02-18 18:22:23 +00:00
let muted = $state($isEventMuted(event))
2024-09-24 21:12:38 +00:00
</script>
<div class="flex flex-col gap-2 {restProps.class}" style={restProps.style}>
2024-10-17 22:58:18 +00:00
{#if muted}
2024-10-17 23:03:50 +00:00
<div class="flex items-center justify-between">
<div class="flex gap-2 relative">
2025-09-10 22:26:39 +00:00
<Icon icon={Danger} class="mt-1" />
2024-10-17 23:03:50 +00:00
<p>You have muted this person.</p>
2024-10-17 22:58:18 +00:00
</div>
<Button class="link ml-8" onclick={ignoreMute}>Show anyway</Button>
2024-10-17 22:58:18 +00:00
</div>
{:else}
<!-- The size container is the header, not the card: container-type contains a box's inline
size, so a card that is its own container reports no width to an ancestor sized by its
contents and collapses a quote inside a chat bubble. The header fills the card either way,
so the query still measures the card's width. -->
<div class="@container flex items-start justify-between gap-2">
2024-10-17 22:58:18 +00:00
{#if !hideProfile}
2024-11-21 22:14:46 +00:00
{#if minimal}
2025-04-15 18:03:27 +00:00
@<ProfileName pubkey={event.pubkey} {url} />
2024-11-21 22:14:46 +00:00
{:else}
2025-04-15 18:03:27 +00:00
<Profile pubkey={event.pubkey} {url} />
2024-11-21 22:14:46 +00:00
{/if}
2024-10-17 22:58:18 +00:00
{/if}
2025-11-14 19:35:19 +00:00
<Button
2026-06-23 23:30:54 +00:00
class={cx("text-sm opacity-75 @max-sm:hidden", {"text-xs": minimal})}
2026-07-28 16:16:26 +00:00
onclick={goToNote}>
2024-10-17 22:58:18 +00:00
{formatTimestamp(event.created_at)}
2025-11-14 19:35:19 +00:00
</Button>
2024-10-17 22:58:18 +00:00
</div>
2026-06-24 20:10:06 +00:00
{@render children?.()}
2024-10-17 22:58:18 +00:00
{/if}
2024-09-24 21:12:38 +00:00
</div>