import { useState, useEffect } from 'react'; import { Highlight, SectionType } from '../types'; import { getHighlights, removeHighlight } from '../utils/storage'; interface Props { refreshKey: number; onViewPaper: (paperId: string) => void; } const SECTION_LABELS: Record = { abstract: '摘要 Abstract', introduction: '引言 Introduction', relatedWork: '相关工作 Related Work', methods: '方法 Methods', }; export default function HighlightsView({ refreshKey, onViewPaper }: Props) { const [highlights, setHighlights] = useState([]); const [filter, setFilter] = useState('all'); const [searchText, setSearchText] = useState(''); useEffect(() => { setHighlights(getHighlights()); }, [refreshKey]); // Group by paper const grouped = highlights.reduce( (acc, h) => { if (!acc[h.paperId]) { acc[h.paperId] = { title: h.paperTitle, paperId: h.paperId, items: [] }; } acc[h.paperId].items.push(h); return acc; }, {} as Record ); const filteredHighlights = highlights.filter((h) => { if (filter !== 'all' && h.section !== filter) return false; if (searchText && !h.text.toLowerCase().includes(searchText.toLowerCase())) return false; return true; }); const filteredGrouped = Object.values(grouped) .map((group) => ({ ...group, items: group.items.filter((h) => { if (filter !== 'all' && h.section !== filter) return false; if (searchText && !h.text.toLowerCase().includes(searchText.toLowerCase())) return false; return true; }), })) .filter((group) => group.items.length > 0); const handleDelete = (id: string) => { removeHighlight(id); setHighlights(getHighlights()); }; const exportHighlights = () => { const text = filteredHighlights .map( (h) => `"${h.text}"\n — ${h.paperTitle} (${h.paperId}), ${SECTION_LABELS[h.section]}\n ${new Date(h.timestamp).toLocaleString()}\n` ) .join('\n---\n\n'); const blob = new Blob([text], { type: 'text/plain;charset=utf-8' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `arxiv_highlights_${new Date().toISOString().slice(0, 10)}.txt`; a.click(); URL.revokeObjectURL(url); }; return (

📌 文本收藏 Highlights ({highlights.length} 条)

{highlights.length > 0 && ( )}
{/* Filters */} {highlights.length > 0 && (
setSearchText(e.target.value)} placeholder="搜索收藏内容 Search highlights..." className="px-4 py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 w-64" />
{(['abstract', 'introduction', 'relatedWork', 'methods'] as SectionType[]).map( (section) => ( ) )}
)} {filteredGrouped.length === 0 ? (
📌

暂无文本收藏

No highlights saved yet

在论文详情中选中文本即可收藏

Select text in paper detail to save highlights

) : (
{filteredGrouped.map((group) => (
{/* Paper Header */}
📄 {group.title} {group.paperId}
{/* Highlights */}
{group.items.map((highlight) => (
"

{highlight.text}

{SECTION_LABELS[highlight.section]} {new Date(highlight.timestamp).toLocaleString()}
))}
))}
)}
); }