import { Copy, Folder, Hash, MoreVertical, Pin, PinOff, Plus, Search, Trash2, X, } from "lucide-react"; import React, { useMemo, useState } from "react"; import { useI18n } from "../../application/i18n/I18nProvider"; import { extractNoteSnippet, filterAndSortVaultNotes, getNoteGroupLeafName, type NoteFilterMode, type NoteSortOption, type VaultNote, } from "../../domain/notes"; import type { Host } from "../../types"; export interface NotesListProps { notes: VaultNote[]; selectedNoteId: string | null; selectedGroup: string | null; selectedTag: string | null; filterMode: NoteFilterMode; hosts?: Host[]; onSelectNote: (noteId: string) => void; onCreateNote: () => void; onTogglePinNote: (noteId: string) => void; onDuplicateNote: (note: VaultNote) => void; onDeleteNote: (noteId: string) => void; className?: string; } function formatNoteRelativeTime(timestamp: number): string { if (!timestamp || !Number.isFinite(timestamp)) return ""; const diff = Date.now() - timestamp; const minute = 60 * 1000; const hour = 60 * minute; const day = 24 * hour; if (diff < minute) return "刚刚"; if (diff < hour) return `${Math.floor(diff / minute)} 分钟前`; if (diff < day) { const d = new Date(timestamp); return `${d.getHours().toString().padStart(2, "0")}:${d .getMinutes() .toString() .padStart(2, "0")}`; } if (diff < 2 * day) return "昨天"; if (diff < 365 * day) { const d = new Date(timestamp); return `${d.getMonth() + 1}月${d.getDate()}日`; } const d = new Date(timestamp); return `${d.getFullYear()}/${d.getMonth() + 1}/${d.getDate()}`; } export const NotesList: React.FC = ({ notes, selectedNoteId, selectedGroup, selectedTag, filterMode, hosts = [], onSelectNote, onCreateNote, onTogglePinNote, onDuplicateNote, onDeleteNote, className = "", }) => { const { t } = useI18n(); const [searchQuery, setSearchQuery] = useState(""); const [sortOption, setSortOption] = useState("updatedDesc"); const [activeMenuNoteId, setActiveMenuNoteId] = useState(null); // Compute title for the list header const headerTitle = useMemo(() => { if (selectedTag) return `#${selectedTag}`; if (selectedGroup) return getNoteGroupLeafName(selectedGroup); if (filterMode === "pinned") return t("notes.pinned") || "已置顶笔记"; if (filterMode === "recent") return t("notes.recent") || "最近修改"; if (filterMode === "uncategorized") return t("notes.uncategorized") || "未分类笔记"; return t("notes.allNotes") || "全部笔记"; }, [selectedTag, selectedGroup, filterMode, t]); // Filter and sort notes const displayedNotes = useMemo(() => { return filterAndSortVaultNotes(notes, { search: searchQuery, group: selectedGroup, tag: selectedTag, filterMode, sort: sortOption, hosts, }); }, [notes, searchQuery, selectedGroup, selectedTag, filterMode, sortOption, hosts]); return (
{/* List Header */}

{headerTitle}

{displayedNotes.length}
{/* Search input */}
setSearchQuery(e.target.value)} placeholder={t("notes.searchPlaceholder") || "搜索笔记标题、内容、标签..."} className="w-full bg-muted/50 focus:bg-background border border-border focus:border-primary/60 rounded-md pl-7 pr-7 py-1.5 text-xs text-foreground placeholder:text-muted-foreground/70 outline-none transition-all" /> {searchQuery && ( )}
{/* Cards List */}
{displayedNotes.length === 0 ? (

暂无匹配笔记

{searchQuery ? (

可尝试更改搜索关键词或清除搜索条件

) : ( )}
) : ( displayedNotes.map((note) => { const isSelected = selectedNoteId === note.id; const snippet = extractNoteSnippet(note.content, 90); const title = note.title.trim() || t("notes.untitled") || "无标题笔记"; const isMenuOpen = activeMenuNoteId === note.id; return (
onSelectNote(note.id)} > {/* Title & Pin Indicator */}
{note.isPinned && ( )} {title}
{/* Actions Dropdown Trigger on hover */}
{isMenuOpen && (
e.stopPropagation()} >
)}
{/* Snippet Preview */} {snippet && (

{snippet}

)} {/* Footer Metadata: Date, Folder, Tags */}
{formatNoteRelativeTime(note.updatedAt)}
{note.group && ( {getNoteGroupLeafName(note.group)} )} {note.tags && note.tags.length > 0 && ( {note.tags[0]} {note.tags.length > 1 && ( +{note.tags.length - 1} )} )}
); }) )}
); };