tahamajs/IE / Projects /front /src /components /publication /PaperCollectionsPanel.tsx
tahamajs's picture
download
raw
4.55 kB
import { useState } from "react";
import { usePaperCollections } from "@/hooks/usePaperCollections";
import { Bookmark, Plus, Check, FolderOpen, Lock, Globe, X, Loader2 } from "lucide-react";
import { motion } from "framer-motion";
interface PaperCollectionsPanelProps {
paperId: string;
paperTitle: string;
authors: string[];
year: number;
onClose: () => void;
}
export function PaperCollectionsPanel({ paperId, paperTitle, authors, year, onClose }: PaperCollectionsPanelProps) {
const { collections, loading, createCollection, addPaperToCollection, removePaperFromCollection, showCreateModal, setShowCreateModal } = usePaperCollections();
const [newName, setNewName] = useState("");
const [newDesc, setNewDesc] = useState("");
const [isPublic, setIsPublic] = useState(false);
return (
<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" onClick={onClose}>
<motion.div initial={{ scale: 0.95 }} animate={{ scale: 1 }}
className="bg-white dark:bg-gray-800 rounded-2xl max-w-md w-full p-6 shadow-xl max-h-[80vh] overflow-y-auto"
onClick={e => e.stopPropagation()}>
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-lg flex items-center gap-2"><Bookmark className="w-5 h-5 text-primary"/> Save to Collection</h3>
<button onClick={onClose} className="text-gray-500 hover:text-gray-700"><X className="w-5 h-5"/></button>
</div>
<p className="text-sm text-gray-500 mb-4 truncate">"{paperTitle}"</p>
{loading ? (
<div className="flex justify-center py-8"><Loader2 className="w-6 h-6 animate-spin text-gray-400"/></div>
) : (
<div className="space-y-2 max-h-48 overflow-y-auto mb-4">
{collections.map(col => {
const isInCollection = col.papers.some(p => p.id === paperId);
return (
<button key={col.id}
onClick={() => isInCollection ? removePaperFromCollection(col.id, paperId) : addPaperToCollection(col.id, { title: paperTitle, authors: authors.join(", "), year })}
className={`w-full flex items-center justify-between p-3 rounded-xl border transition ${
isInCollection ? "border-primary bg-primary/5" : "border-white/20 dark:border-white/10 hover:border-primary/50"
}`}>
<div className="flex items-center gap-2">
<span className="text-lg">{col.icon ?? "📁"}</span>
<div className="text-left">
<p className="text-sm font-semibold">{col.name}</p>
<p className="text-[10px] text-gray-500">{col.paperCount} papers · {col.isPublic ? <Globe className="w-3 h-3 inline"/> : <Lock className="w-3 h-3 inline"/>} {col.isPublic ? "Public" : "Private"}</p>
</div>
</div>
{isInCollection ? <Check className="w-5 h-5 text-primary"/> : <Plus className="w-5 h-5 text-gray-400"/>}
</button>
);
})}
</div>
)}
{showCreateModal ? (
<div className="space-y-3 p-4 border border-dashed border-white/30 rounded-xl">
<input type="text" value={newName} onChange={e => setNewName(e.target.value)} placeholder="Collection name" className="input text-sm" autoFocus />
<input type="text" value={newDesc} onChange={e => setNewDesc(e.target.value)} placeholder="Description (optional)" className="input text-sm" />
<label className="flex items-center gap-2 text-sm">
<input type="checkbox" checked={isPublic} onChange={e => setIsPublic(e.target.checked)} className="rounded"/> Public collection
</label>
<div className="flex gap-2">
<button onClick={() => { createCollection(newName, newDesc, isPublic); setNewName(""); setNewDesc(""); }}
disabled={!newName.trim()} className="btn btn-primary btn-sm flex-1">Create</button>
<button onClick={() => setShowCreateModal(false)} className="btn btn-ghost btn-sm">Cancel</button>
</div>
</div>
) : (
<button onClick={() => setShowCreateModal(true)} className="btn btn-ghost w-full gap-2 text-sm">
<Plus className="w-4 h-4"/> New Collection
</button>
)}
</motion.div>
</motion.div>
);
}

Xet Storage Details

Size:
4.55 kB
·
Xet hash:
c66f56d43deb01b5cf8c9e21170722c89b4f50f1e43931a87709da23b1512128

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.