"use client"; import React, { useEffect } from "react"; import { motion } from "framer-motion"; import { FileIcon, X } from "lucide-react"; interface FilePreviewProps { file: File; onRemove?: () => void; } export const FilePreview = React.forwardRef( (props, ref) => { if (props.file.type.startsWith("image/")) { return ; } if ( props.file.type.startsWith("text/") || props.file.name.endsWith(".txt") || props.file.name.endsWith(".md") ) { return ; } return ; } ); FilePreview.displayName = "FilePreview"; const ImageFilePreview = React.forwardRef( ({ file, onRemove }, ref) => { return (
{/* eslint-disable-next-line @next/next/no-img-element */} {`Attachment {file.name}
{onRemove ? ( ) : null}
); } ); ImageFilePreview.displayName = "ImageFilePreview"; const TextFilePreview = React.forwardRef( ({ file, onRemove }, ref) => { const [preview, setPreview] = React.useState(""); useEffect(() => { const reader = new FileReader(); reader.onload = e => { const text = e.target?.result as string; setPreview(text.slice(0, 50) + (text.length > 50 ? "..." : "")); }; reader.readAsText(file); }, [file]); return (
{preview || "Loading..."}
{file.name}
{onRemove ? ( ) : null}
); } ); TextFilePreview.displayName = "TextFilePreview"; const GenericFilePreview = React.forwardRef( ({ file, onRemove }, ref) => { return (
{file.name}
{onRemove ? ( ) : null}
); } ); GenericFilePreview.displayName = "GenericFilePreview";