/** * PinnedMessageRow — shared card used by the desktop pins popover, * the mobile Pins drawer, and the pin confirmation modal. Matches * the new UI's behaviour: * * - `showHoverActions` (desktop) → card is non-clickable; a "Jump" * button + close X appear on the right side of the meta row and * fire `onJumpTo` / `onUnpin` respectively. * - `showHoverActions === false` (mobile / preview) → whole card * is tappable to `onJumpTo`; no hover buttons. The confirmation * modal renders with `onJumpTo={undefined}` so the card is a * read-only preview. */ import { Flag, X } from '@phosphor-icons/react'; import { Avatar } from '@discord-clone/ui'; import { EncryptedAttachment, type AttachmentMetadata } from './EncryptedAttachment'; import styles from './PinnedMessageRow.module.css'; export interface PinnedMessage { id: string; authorName: string; authorAvatarUrl: string | null; content: string; timestamp: number; attachments?: AttachmentMetadata[]; } interface PinnedMessageRowProps { message: PinnedMessage; /** Handler for navigating to the pinned message. */ onJumpTo?: () => void; /** Handler for unpinning the message. Only rendered when the * caller also enables `showHoverActions`. */ onUnpin?: () => void; /** * Desktop layout flag. When true, the card is not clickable and * the meta row shows a Jump button + close X. When false (mobile * / static preview), the whole card is the button. */ showHoverActions?: boolean; /** Whether the viewer has permission to unpin. Hides the X when * they don't, even if `showHoverActions` is on. */ canUnpin?: boolean; } function formatTimestamp(ts: number): string { const date = new Date(ts); const now = new Date(); const isToday = date.toDateString() === now.toDateString(); const yesterday = new Date(now); yesterday.setDate(yesterday.getDate() - 1); const isYesterday = date.toDateString() === yesterday.toDateString(); const time = date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit', }); if (isToday) return `Today at ${time}`; if (isYesterday) return `Yesterday at ${time}`; return `${date.toLocaleDateString()}, ${time}`; } export function PinnedMessageRow({ message, onJumpTo, onUnpin, showHoverActions = false, canUnpin = true, }: PinnedMessageRowProps) { const isClickable = !showHoverActions && !!onJumpTo; const handleCardClick = () => { if (isClickable && onJumpTo) onJumpTo(); }; const handleJumpClick = (e: React.MouseEvent) => { e.stopPropagation(); onJumpTo?.(); }; const handleUnpinClick = (e: React.MouseEvent) => { e.stopPropagation(); onUnpin?.(); }; return (