"use client"; import { useRef } from "react"; /** File types accepted by the scientist file upload. */ const ACCEPTED_EXTENSIONS = ".fasta,.fa,.pdb,.cif"; function formatSize(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } interface FileUploadProps { file: File | null; onFileChange: (file: File | null) => void; disabled?: boolean; } /** * Paperclip-style file upload button for scientist-provided PDB/FASTA input. * Shows a small chip with filename + size when a file is selected. */ export default function FileUpload({ file, onFileChange, disabled }: FileUploadProps) { const inputRef = useRef(null); const handleClick = () => { if (disabled) return; inputRef.current?.click(); }; const handleChange = (e: React.ChangeEvent) => { const selected = e.target.files?.[0] ?? null; onFileChange(selected); // Reset so the same file can be re-selected if (inputRef.current) inputRef.current.value = ""; }; return (
{/* Paperclip button */} {/* File chip */} {file && ( {file.name} ({formatSize(file.size)}) )}
); }