Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

1.2 KB
Raw Blame
import Image from 'next/image';
import { FileIcon } from 'lucide-react';
import {
  isImage,
  isSvg,
  isVideo,
  type Embeddable,
} from '@/components/common/editor/attachmentEmbed';

// An attachment's leading thumbnail: images and videos preview themselves,
// every other type falls back to a generic file glyph.
export default function AttachmentThumb({
  attachment,
  sizes = '40px',
}: {
  attachment: Embeddable;
  // The rendered width, for the image optimizer. The default is the w-10 (40px)
  // thumbnail every card uses; a larger preview passes its own.
  sizes?: string;
}) {
  if (isImage(attachment))
    return (
      <Image
        src={attachment.url}
        alt={attachment.filename}
        fill
        sizes={sizes}
        // A file picked in the new issue modal is previewed from a local blob:
        // URL, which the image optimizer cannot fetch; it refuses SVG.
        unoptimized={attachment.url.startsWith('blob:') || isSvg(attachment)}
        draggable={false}
        className="object-cover"
      />
    );
  if (isVideo(attachment))
    return (
      <video src={attachment.url} className="size-full object-cover" muted draggable={false} />
    );
  return <FileIcon className="text-muted-foreground" />;
}