'use client'; import { memo } from 'react'; import { Trash2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { useObjectUrls } from '@/components/video-page/hooks/use-object-urls'; import type { CommentImage } from '@/components/video-page/types'; interface ImageAttachmentStripProps { /** Images already saved on the comment being edited, if any. */ existingUrls?: string[]; onRemoveExisting?: (url: string) => void; /** Files staged in this editor and not uploaded yet. */ files: File[]; onRemoveFile: (index: number) => void; compact?: boolean; className?: string; } /** * The row of thumbnails under an editor, showing what will be sent with it. * Saved images come first, then the ones staged in this session. */ export const ImageAttachmentStrip = memo(function ImageAttachmentStrip({ existingUrls = [], onRemoveExisting, files, onRemoveFile, compact = false, className, }: ImageAttachmentStripProps) { const previewUrls = useObjectUrls(files); if (existingUrls.length === 0 && previewUrls.length === 0) return null; const tileSize = compact ? 'h-14 w-14' : 'h-20 w-20'; const buttonSize = compact ? 'h-5 w-5' : 'h-6 w-6'; const iconSize = compact ? 'h-2.5 w-2.5' : 'h-3 w-3'; const tile = (key: string, src: string, alt: string, onRemove: () => void) => (
{/* eslint-disable-next-line @next/next/no-img-element */} {alt}
); return (
{existingUrls.map((url, index) => tile(url, url, `Attachment ${index + 1}`, () => onRemoveExisting?.(url)) )} {previewUrls.map((url, index) => tile(`staged-${index}`, url, `Preview ${index + 1}`, () => onRemoveFile(index)) )}
); }); interface CommentImageGalleryProps { images: CommentImage[]; onOpen: (url: string) => void; compact?: boolean; className?: string; } /** The images saved on a comment. One fills the width; several tile into a grid. */ export const CommentImageGallery = memo(function CommentImageGallery({ images, onOpen, compact = false, className, }: CommentImageGalleryProps) { if (images.length === 0) return null; if (images.length === 1) { return (
onOpen(images[0].url)} > {/* eslint-disable-next-line @next/next/no-img-element */} Attachment
); } return (
{images.map((image, index) => (
onOpen(image.url)} > {/* eslint-disable-next-line @next/next/no-img-element */} {`Attachment
))}
); });