diff --git a/src/components/NoteList.tsx b/src/components/NoteList.tsx index f348da9f..f6631571 100644 --- a/src/components/NoteList.tsx +++ b/src/components/NoteList.tsx @@ -1,6 +1,6 @@ import { useState, useMemo, useCallback, memo } from 'react' import { Virtuoso } from 'react-virtuoso' -import type { VaultEntry, SidebarSelection, NoteStatus } from '../types' +import type { VaultEntry, SidebarSelection, ModifiedFile, NoteStatus } from '../types' import { Input } from '@/components/ui/input' import { MagnifyingGlass, Plus, CaretDown, CaretRight, Warning, @@ -21,6 +21,7 @@ interface NoteListProps { selection: SidebarSelection selectedNote: VaultEntry | null allContent: Record + modifiedFiles?: ModifiedFile[] getNoteStatus?: (path: string) => NoteStatus onSelectNote: (entry: VaultEntry) => void onReplaceActiveTab: (entry: VaultEntry) => void @@ -250,12 +251,26 @@ function useNoteListData({ entries, selection, allContent, query, listSort, list const defaultGetNoteStatus = (): NoteStatus => 'clean' -function NoteListInner({ entries, selection, selectedNote, allContent, getNoteStatus = defaultGetNoteStatus, onSelectNote, onReplaceActiveTab, onCreateNote }: NoteListProps) { +function NoteListInner({ entries, selection, selectedNote, allContent, modifiedFiles, getNoteStatus, onSelectNote, onReplaceActiveTab, onCreateNote }: NoteListProps) { const [search, setSearch] = useState('') const [searchVisible, setSearchVisible] = useState(false) const [collapsedGroups, setCollapsedGroups] = useState>(new Set()) const [sortPrefs, setSortPrefs] = useState>(loadSortPreferences) + const modifiedPathSet = useMemo( + () => new Set((modifiedFiles ?? []).map((f) => f.path)), + [modifiedFiles], + ) + + // Resolve note status: prefer explicit getNoteStatus prop; fall back to modifiedFiles-derived status + const resolvedGetNoteStatus = useMemo<(path: string) => NoteStatus>(() => { + if (getNoteStatus) return getNoteStatus + if (modifiedFiles && modifiedFiles.length > 0) { + return (path: string) => modifiedPathSet.has(path) ? 'modified' : 'clean' + } + return defaultGetNoteStatus + }, [getNoteStatus, modifiedFiles, modifiedPathSet]) + const handleSortChange = useCallback((groupLabel: string, option: SortOption, direction: SortDirection) => { setSortPrefs((prev) => { const next = { ...prev, [groupLabel]: { option, direction } }; saveSortPreferences(next); return next }) }, []) @@ -276,8 +291,8 @@ function NoteListInner({ entries, selection, selectedNote, allContent, getNoteSt }, [onSelectNote, onReplaceActiveTab]) const renderItem = useCallback((entry: VaultEntry) => ( - - ), [selectedNote?.path, handleClickNote, typeEntryMap, getNoteStatus]) + + ), [selectedNote?.path, handleClickNote, typeEntryMap, resolvedGetNoteStatus]) return (