"use client"; import { useRef, useState } from "react"; import type { UploadedDoc } from "@/lib/query"; import { cn } from "@/lib/utils"; export function UploadPanel({ isUploading, uploadSeconds, uploadError, uploadedDoc, onFileSelect, }: { isUploading: boolean; uploadSeconds: number; uploadError: string | null; uploadedDoc: UploadedDoc | null; onFileSelect: (file: File) => void; }) { const inputRef = useRef(null); const [isDragging, setIsDragging] = useState(false); function pickFile(file: File | undefined | null) { if (file) onFileSelect(file); } return (
Your document
{uploadedDoc && !isUploading && ( )} {isUploading && ( )}
{ pickFile(event.target.files?.[0]); event.target.value = ""; }} className="sr-only" />
!isUploading && inputRef.current?.click()} onKeyDown={(event) => { if (!isUploading && (event.key === "Enter" || event.key === " ")) { event.preventDefault(); inputRef.current?.click(); } }} onDragOver={(event) => { event.preventDefault(); if (!isUploading) setIsDragging(true); }} onDragLeave={() => setIsDragging(false)} onDrop={(event) => { event.preventDefault(); setIsDragging(false); if (!isUploading) pickFile(event.dataTransfer.files?.[0]); }} className={cn( "flex cursor-pointer flex-col items-center justify-center gap-2 rounded-[6px] border border-dashed px-4 py-5 text-center transition-colors", isUploading && "cursor-not-allowed opacity-60", isDragging ? "border-[#d62839] bg-[#fdeaea]/60" : "border-[#111111]/20 bg-[#fafafa] hover:border-[#d62839]/50 hover:bg-[#fff7f7]" )} >
{isDragging ? "Drop to upload" : isUploading ? "Uploading…" : "Choose a file or drop it here"}
PDF · DOCX · HTML · Markdown
{isUploading && (
Parsing, embedding and indexing… {uploadSeconds}s elapsed
The first upload can take about a minute while the embedding model loads.
)} {uploadError && (
{uploadError}
)} {uploadedDoc && !isUploading && (
{uploadedDoc.title}
{uploadedDoc.chunk_count ?? 0} chunks indexed · answers drawn only from this document
)}
); }