| // src/components/gap-analysis/PaperIngestionPanel.tsx | |
| import { useState, useCallback } from "react"; | |
| import { useGapAnalysis } from "@/hooks/useGapAnalysis"; | |
| import type { AnalysisPaper } from "@/types/gap-analysis"; | |
| import { | |
| Upload, FileText, Link, Search, Loader2, CheckCircle2, | |
| X, Database, Trash2, BookOpen, Globe, | |
| } from "lucide-react"; | |
| import { useDragDropOverlay } from "@/hooks/useDragDropOverlay"; | |
| interface PaperIngestionPanelProps { | |
| papers: AnalysisPaper[]; | |
| status: string; | |
| progress: number; | |
| onIngest: (sources: any) => Promise<void>; | |
| onClear: () => void; | |
| } | |
| export function PaperIngestionPanel({ | |
| papers, status, progress, onIngest, onClear, | |
| }: PaperIngestionPanelProps) { | |
| const [activeTab, setActiveTab] = useState<"upload" | "query" | "articles">("upload"); | |
| const [files, setFiles] = useState<File[]>([]); | |
| const [query, setQuery] = useState(""); | |
| const [maxResults, setMaxResults] = useState(20); | |
| const [articleIds, setArticleIds] = useState(""); | |
| const { isDragging } = useDragDropOverlay(); | |
| const isProcessing = status === "ingesting" || status === "analyzing"; | |
| const handleUpload = async () => { | |
| if (activeTab === "upload" && files.length > 0) { | |
| await onIngest({ type: "upload", files }); | |
| setFiles([]); | |
| } else if (activeTab === "query" && query.trim()) { | |
| await onIngest({ type: "query", query: query.trim(), maxResults }); | |
| setQuery(""); | |
| } else if (activeTab === "articles" && articleIds.trim()) { | |
| const ids = articleIds.split(",").map((s) => parseInt(s.trim())).filter((n) => !isNaN(n)); | |
| await onIngest({ type: "article", articleIds: ids }); | |
| setArticleIds(""); | |
| } | |
| }; | |
| const removeFile = (idx: number) => setFiles((prev) => prev.filter((_, i) => i !== idx)); | |
| return ( | |
| <div className="bg-white dark:bg-gray-800 rounded-2xl border border-gray-200 dark:border-gray-700"> | |
| <div className="p-4 border-b border-gray-100 dark:border-gray-700"> | |
| <h3 className="font-bold text-lg flex items-center gap-2"> | |
| <Database className="w-5 h-5 text-primary" /> | |
| Paper Library | |
| <span className="text-sm font-normal text-gray-400 ml-1"> | |
| ({papers.length} papers) | |
| </span> | |
| </h3> | |
| {/* Tabs */} | |
| <div className="flex bg-gray-100 dark:bg-gray-700 rounded-xl p-1 mt-3"> | |
| {[ | |
| { key: "upload", icon: Upload, label: "Upload" }, | |
| { key: "query", icon: Search, label: "Search" }, | |
| { key: "articles", icon: BookOpen, label: "Articles" }, | |
| ].map((tab) => ( | |
| <button | |
| key={tab.key} | |
| onClick={() => setActiveTab(tab.key as any)} | |
| className={`flex-1 flex items-center justify-center gap-1.5 py-2 text-xs font-medium rounded-lg transition ${ | |
| activeTab === tab.key | |
| ? "bg-white dark:bg-gray-600 shadow text-primary" | |
| : "text-gray-500" | |
| }`} | |
| > | |
| <tab.icon className="w-3.5 h-3.5" /> | |
| {tab.label} | |
| </button> | |
| ))} | |
| </div> | |
| </div> | |
| <div className="p-4 space-y-4"> | |
| {/* Upload tab */} | |
| {activeTab === "upload" && ( | |
| <div> | |
| <div | |
| className={`border-2 border-dashed rounded-xl p-6 text-center transition ${ | |
| isDragging ? "border-primary bg-primary/5" : "border-gray-300 dark:border-gray-700" | |
| }`} | |
| onDragOver={(e) => e.preventDefault()} | |
| onDrop={(e) => { | |
| e.preventDefault(); | |
| setFiles((prev) => [...prev, ...Array.from(e.dataTransfer.files)]); | |
| }} | |
| > | |
| <input | |
| type="file" | |
| multiple | |
| accept=".pdf,.txt,.md" | |
| className="absolute inset-0 opacity-0 cursor-pointer" | |
| onChange={(e) => setFiles((prev) => [...prev, ...Array.from(e.target.files ?? [])])} | |
| /> | |
| <Upload className="w-8 h-8 text-gray-400 mx-auto mb-2" /> | |
| <p className="text-sm text-gray-600 dark:text-gray-400"> | |
| Drop PDFs, text files, or click to browse | |
| </p> | |
| </div> | |
| {files.length > 0 && ( | |
| <div className="mt-3 space-y-1 max-h-32 overflow-y-auto"> | |
| {files.map((f, i) => ( | |
| <div key={i} className="flex items-center justify-between text-xs p-2 bg-gray-50 dark:bg-gray-700/50 rounded-lg"> | |
| <span className="truncate">{f.name}</span> | |
| <button onClick={() => removeFile(i)} className="text-red-400 hover:text-red-600"> | |
| <X className="w-3.5 h-3.5" /> | |
| </button> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {/* Search tab */} | |
| {activeTab === "query" && ( | |
| <div> | |
| <textarea | |
| value={query} | |
| onChange={(e) => setQuery(e.target.value)} | |
| placeholder="Describe the research area to find papers... e.g., 'deep learning approaches for protein folding prediction after 2022'" | |
| rows={3} | |
| className="w-full p-3 border border-gray-200 dark:border-gray-700 rounded-xl bg-transparent focus:ring-2 focus:ring-primary text-sm resize-none" | |
| /> | |
| <div className="flex items-center gap-2 mt-2"> | |
| <span className="text-xs text-gray-500">Max results:</span> | |
| <select | |
| value={maxResults} | |
| onChange={(e) => setMaxResults(parseInt(e.target.value))} | |
| className="text-xs border rounded-lg px-2 py-1 bg-transparent" | |
| > | |
| {[5, 10, 20, 50].map((n) => ( | |
| <option key={n} value={n}>{n}</option> | |
| ))} | |
| </select> | |
| </div> | |
| </div> | |
| )} | |
| {/* Articles tab */} | |
| {activeTab === "articles" && ( | |
| <div> | |
| <textarea | |
| value={articleIds} | |
| onChange={(e) => setArticleIds(e.target.value)} | |
| placeholder="Paste article IDs, separated by commas... e.g., 42, 57, 103" | |
| rows={2} | |
| className="w-full p-3 border border-gray-200 dark:border-gray-700 rounded-xl bg-transparent focus:ring-2 focus:ring-primary text-sm resize-none" | |
| /> | |
| </div> | |
| )} | |
| {/* Action buttons */} | |
| <div className="flex gap-2"> | |
| <button | |
| onClick={handleUpload} | |
| disabled={ | |
| isProcessing || | |
| (activeTab === "upload" && files.length === 0) || | |
| (activeTab === "query" && !query.trim()) || | |
| (activeTab === "articles" && !articleIds.trim()) | |
| } | |
| className="btn btn-primary flex-1 gap-2" | |
| > | |
| {isProcessing ? ( | |
| <Loader2 className="w-4 h-4 animate-spin" /> | |
| ) : ( | |
| <Search className="w-4 h-4" /> | |
| )} | |
| {isProcessing | |
| ? `Processing... ${progress}%` | |
| : activeTab === "upload" | |
| ? `Ingest ${files.length} file${files.length !== 1 ? "s" : ""}` | |
| : "Search & Ingest"} | |
| </button> | |
| {papers.length > 0 && ( | |
| <button onClick={onClear} className="btn btn-ghost text-red-500 gap-1"> | |
| <Trash2 className="w-4 h-4" /> Clear | |
| </button> | |
| )} | |
| </div> | |
| {/* Progress bar */} | |
| {isProcessing && ( | |
| <div className="h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden"> | |
| <div | |
| className="h-full bg-primary rounded-full transition-all duration-500" | |
| style={{ width: `${progress}%` }} | |
| /> | |
| </div> | |
| )} | |
| {/* Paper list */} | |
| {papers.length > 0 && ( | |
| <div className="max-h-48 overflow-y-auto space-y-1"> | |
| <h4 className="text-xs font-semibold text-gray-500 uppercase">Ingested Papers</h4> | |
| {papers.map((paper) => ( | |
| <div | |
| key={paper.id} | |
| className="flex items-center justify-between text-xs p-2 bg-gray-50 dark:bg-gray-700/50 rounded-lg" | |
| > | |
| <div className="flex items-center gap-2 truncate"> | |
| <FileText className="w-3.5 h-3.5 text-gray-400 shrink-0" /> | |
| <span className="truncate">{paper.title}</span> | |
| </div> | |
| <span className="text-gray-400 shrink-0 ml-2">{paper.year}</span> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| } |
Xet Storage Details
- Size:
- 8.73 kB
- Xet hash:
- aad55db04646ce652a35eae06b1f7a391a309f8a4ff0ab13bc9a0ad45e4c58f3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.