File size: 5,113 Bytes
7c012de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { X, Download, Trash2 } from "lucide-react";
import { type Citation } from "@shared/schema";
interface CitationPanelProps {
citations: Citation[];
isVisible: boolean;
onClose: () => void;
onRemoveCitation: (citationId: number) => void;
}
export default function CitationPanel({
citations,
isVisible,
onClose,
onRemoveCitation
}: CitationPanelProps) {
if (!isVisible) return null;
const handleExportCitations = () => {
const citationText = citations
.map((citation, index) => {
return `[${index + 1}] ${citation.citationText}${citation.section ? ` (${citation.section})` : ''}${citation.pageNumber ? ` - Page ${citation.pageNumber}` : ''}`;
})
.join('\n\n');
const blob = new Blob([citationText], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'citations.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
return (
<div className="fixed bottom-6 right-6 z-50">
<div className="bg-white rounded-xl shadow-lg border border-slate-200 w-80 max-h-96 flex flex-col">
{/* Header */}
<div className="flex items-center justify-between p-4 border-b border-slate-200">
<div className="flex items-center gap-2">
<h4 className="font-medium text-slate-900">Active Citations</h4>
<Badge variant="secondary" className="text-xs">
{citations.length}
</Badge>
</div>
<Button
variant="ghost"
size="sm"
onClick={onClose}
className="text-slate-400 hover:text-slate-600 p-1"
>
<X className="w-4 h-4" />
</Button>
</div>
{/* Citations List */}
<div className="flex-1 overflow-y-auto p-4">
{citations.length === 0 ? (
<div className="text-center py-8">
<div className="text-slate-400 mb-2">
<svg className="w-8 h-8 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1} d="M9 12h6m-6-4h6m2 5.291A7.962 7.962 0 0112 15c-2.34 0-4.447-.935-6-2.45" />
</svg>
</div>
<p className="text-sm text-slate-500">No citations added yet</p>
<p className="text-xs text-slate-400 mt-1">
Click "Add Citation" on search results to build your reference list
</p>
</div>
) : (
<div className="space-y-3">
{citations.map((citation, index) => (
<div
key={citation.id}
className="group flex items-start gap-3 p-3 bg-slate-50 rounded-lg hover:bg-slate-100 transition-colors"
>
<span className="w-6 h-6 bg-blue-600 text-white rounded-full flex items-center justify-center text-xs font-medium flex-shrink-0 mt-0.5">
{index + 1}
</span>
<div className="flex-1 min-w-0">
<p className="text-sm text-slate-700 leading-relaxed line-clamp-3">
{citation.citationText}
</p>
{(citation.section || citation.pageNumber) && (
<div className="flex items-center gap-2 mt-2">
{citation.section && (
<span className="text-xs text-slate-500 bg-white px-2 py-1 rounded">
{citation.section}
</span>
)}
{citation.pageNumber && (
<span className="text-xs text-slate-500 bg-white px-2 py-1 rounded">
Page {citation.pageNumber}
</span>
)}
</div>
)}
</div>
<Button
variant="ghost"
size="sm"
onClick={() => onRemoveCitation(citation.id)}
className="opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-red-600 p-1"
>
<Trash2 className="w-3 h-3" />
</Button>
</div>
))}
</div>
)}
</div>
{/* Footer */}
{citations.length > 0 && (
<div className="p-4 border-t border-slate-200">
<Button
onClick={handleExportCitations}
className="w-full bg-slate-100 text-slate-700 hover:bg-slate-200"
size="sm"
>
<Download className="w-4 h-4 mr-2" />
Export Citations
</Button>
</div>
)}
</div>
</div>
);
}
|