2026-02-22 10:18:05 +01:00
|
|
|
import { useState, useMemo, useCallback, memo } from 'react'
|
2026-02-25 21:43:16 +01:00
|
|
|
import { useDragRegion } from '../hooks/useDragRegion'
|
2026-02-23 21:11:41 +01:00
|
|
|
import { Virtuoso } from 'react-virtuoso'
|
2026-02-24 16:35:47 +01:00
|
|
|
import type { VaultEntry, SidebarSelection, ModifiedFile, NoteStatus } from '../types'
|
2026-02-16 16:56:44 +01:00
|
|
|
import { Input } from '@/components/ui/input'
|
2026-02-17 18:45:34 +01:00
|
|
|
import {
|
2026-02-22 10:18:05 +01:00
|
|
|
MagnifyingGlass, Plus, CaretDown, CaretRight, Warning,
|
2026-02-17 18:45:34 +01:00
|
|
|
} from '@phosphor-icons/react'
|
2026-02-26 04:05:22 +01:00
|
|
|
import { getTypeColor, getTypeLightColor, buildTypeEntryMap } from '../utils/typeColors'
|
2026-02-22 10:18:05 +01:00
|
|
|
import { NoteItem, getTypeIcon } from './NoteItem'
|
|
|
|
|
import { SortDropdown } from './SortDropdown'
|
|
|
|
|
import {
|
2026-02-22 12:08:53 +01:00
|
|
|
type SortOption, type SortDirection, type SortConfig, type RelationshipGroup,
|
2026-02-22 12:13:08 +01:00
|
|
|
getSortComparator,
|
2026-02-22 10:18:05 +01:00
|
|
|
buildRelationshipGroups, filterEntries,
|
2026-02-26 20:50:29 +01:00
|
|
|
formatSubtitle,
|
2026-02-22 10:18:05 +01:00
|
|
|
loadSortPreferences, saveSortPreferences,
|
|
|
|
|
} from '../utils/noteListHelpers'
|
2026-02-17 18:45:34 +01:00
|
|
|
|
2026-02-14 18:22:42 +01:00
|
|
|
interface NoteListProps {
|
|
|
|
|
entries: VaultEntry[]
|
2026-02-14 19:44:39 +01:00
|
|
|
selection: SidebarSelection
|
2026-02-14 20:07:23 +01:00
|
|
|
selectedNote: VaultEntry | null
|
2026-02-14 21:22:54 +01:00
|
|
|
allContent: Record<string, string>
|
2026-02-24 16:35:47 +01:00
|
|
|
modifiedFiles?: ModifiedFile[]
|
2026-02-24 15:54:24 +01:00
|
|
|
getNoteStatus?: (path: string) => NoteStatus
|
2026-02-14 20:07:23 +01:00
|
|
|
onSelectNote: (entry: VaultEntry) => void
|
2026-02-23 20:12:54 +01:00
|
|
|
onReplaceActiveTab: (entry: VaultEntry) => void
|
2026-02-14 21:14:16 +01:00
|
|
|
onCreateNote: () => void
|
2026-02-14 19:44:39 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 20:50:29 +01:00
|
|
|
function PinnedCard({ entry, typeEntryMap, onClickNote }: {
|
2026-02-22 10:18:05 +01:00
|
|
|
entry: VaultEntry
|
|
|
|
|
typeEntryMap: Record<string, VaultEntry>
|
2026-02-23 20:12:54 +01:00
|
|
|
onClickNote: (entry: VaultEntry, e: React.MouseEvent) => void
|
2026-02-22 10:18:05 +01:00
|
|
|
}) {
|
|
|
|
|
const te = typeEntryMap[entry.isA ?? '']
|
|
|
|
|
const color = getTypeColor(entry.isA ?? '', te?.color)
|
|
|
|
|
const bgColor = getTypeLightColor(entry.isA ?? '', te?.color)
|
2026-02-22 12:08:53 +01:00
|
|
|
const Icon = getTypeIcon(entry.isA, te?.icon)
|
2026-02-22 10:18:05 +01:00
|
|
|
return (
|
2026-02-23 20:12:54 +01:00
|
|
|
<div className="relative cursor-pointer border-b border-[var(--border)]" style={{ backgroundColor: bgColor, padding: '14px 16px' }} onClick={(e: React.MouseEvent) => onClickNote(entry, e)}>
|
2026-02-23 08:53:43 +01:00
|
|
|
{/* eslint-disable-next-line react-hooks/static-components */}
|
2026-02-22 10:18:05 +01:00
|
|
|
<Icon width={16} height={16} className="absolute right-3 top-3.5" style={{ color }} data-testid="type-icon" />
|
|
|
|
|
<div className="pr-6 text-[14px] font-bold" style={{ color }}>{entry.title}</div>
|
2026-02-26 20:50:29 +01:00
|
|
|
<div className="mt-1 text-[11px] opacity-60" style={{ color }}>{formatSubtitle(entry)}</div>
|
2026-02-22 10:18:05 +01:00
|
|
|
</div>
|
|
|
|
|
)
|
2026-02-21 17:09:29 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
function RelationshipGroupSection({ group, isCollapsed, sortPrefs, onToggle, handleSortChange, renderItem }: {
|
|
|
|
|
group: RelationshipGroup
|
|
|
|
|
isCollapsed: boolean
|
2026-02-22 12:08:53 +01:00
|
|
|
sortPrefs: Record<string, SortConfig>
|
2026-02-22 10:18:05 +01:00
|
|
|
onToggle: () => void
|
2026-02-22 12:08:53 +01:00
|
|
|
handleSortChange: (groupLabel: string, option: SortOption, direction: SortDirection) => void
|
2026-02-22 10:18:05 +01:00
|
|
|
renderItem: (entry: VaultEntry) => React.ReactNode
|
|
|
|
|
}) {
|
2026-02-22 12:08:53 +01:00
|
|
|
const groupConfig = sortPrefs[group.label] ?? { option: 'modified' as SortOption, direction: 'desc' as SortDirection }
|
|
|
|
|
const sortedEntries = [...group.entries].sort(getSortComparator(groupConfig.option, groupConfig.direction))
|
2026-02-22 10:18:05 +01:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex w-full items-center justify-between bg-muted" style={{ height: 32, padding: '0 16px' }}>
|
|
|
|
|
<button className="flex flex-1 items-center gap-1.5 border-none bg-transparent cursor-pointer p-0" onClick={onToggle}>
|
|
|
|
|
<span className="font-mono-label text-muted-foreground">{group.label}</span>
|
|
|
|
|
<span className="font-mono-label text-muted-foreground" style={{ fontWeight: 400 }}>{group.entries.length}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<span className="flex items-center gap-1.5">
|
2026-02-22 12:08:53 +01:00
|
|
|
<SortDropdown groupLabel={group.label} current={groupConfig.option} direction={groupConfig.direction} onChange={handleSortChange} />
|
2026-02-22 10:18:05 +01:00
|
|
|
<button className="flex items-center border-none bg-transparent cursor-pointer p-0 text-muted-foreground" onClick={onToggle}>
|
|
|
|
|
{isCollapsed ? <CaretRight size={12} /> : <CaretDown size={12} />}
|
|
|
|
|
</button>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{!isCollapsed && sortedEntries.map((entry) => renderItem(entry))}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
feat: implement context view in NoteList
When a note is selected from the sidebar (entity selection), NoteList
now shows a context view instead of a flat list:
- Prominent top card with type-colored background, bold title, snippet,
timestamp, and type icon
- Grouped relationship sections (Children, Events, Referenced By,
Belongs To, Related To, Backlinks) with collapse/expand chevrons
- Backlinks detected by scanning allContent for wikilink references
- Groups show ALL-CAPS headers with count and CaretDown/CaretRight toggle
- Normal flat list shown when sidebar selection is "All Notes"
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 18:47:38 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
function TrashWarningBanner({ expiredCount }: { expiredCount: number }) {
|
|
|
|
|
if (expiredCount === 0) return null
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-start gap-2 border-b border-[var(--border)]" style={{ padding: '10px 12px', background: 'color-mix(in srgb, var(--destructive) 6%, transparent)' }}>
|
|
|
|
|
<Warning size={16} className="shrink-0" style={{ color: 'var(--destructive)', marginTop: 1 }} />
|
|
|
|
|
<div>
|
|
|
|
|
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--destructive)' }}>Notes in trash for 30+ days will be permanently deleted</div>
|
|
|
|
|
<div className="text-muted-foreground" style={{ fontSize: 11 }}>{expiredCount} {expiredCount === 1 ? 'note is' : 'notes are'} past the 30-day retention period</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2026-02-17 19:11:01 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
function EmptyMessage({ text }: { text: string }) {
|
|
|
|
|
return <div className="px-4 py-8 text-center text-[13px] text-muted-foreground">{text}</div>
|
2026-02-15 10:30:13 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
function resolveHeaderTitle(selection: SidebarSelection, typeDocument: VaultEntry | null): string {
|
|
|
|
|
if (selection.kind === 'entity') return selection.entry.title
|
|
|
|
|
if (typeDocument) return typeDocument.title
|
|
|
|
|
if (selection.kind === 'filter' && selection.filter === 'archived') return 'Archive'
|
|
|
|
|
if (selection.kind === 'filter' && selection.filter === 'trash') return 'Trash'
|
2026-02-24 14:42:06 +01:00
|
|
|
if (selection.kind === 'filter' && selection.filter === 'changes') return 'Changes'
|
2026-02-22 10:18:05 +01:00
|
|
|
return 'Notes'
|
2026-02-14 19:44:39 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
function useTypeEntryMap(entries: VaultEntry[]) {
|
2026-02-26 04:05:22 +01:00
|
|
|
return useMemo(() => buildTypeEntryMap(entries), [entries])
|
2026-02-21 17:09:29 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
// --- View sub-components ---
|
2026-02-14 19:46:44 +01:00
|
|
|
|
2026-02-23 20:12:54 +01:00
|
|
|
function EntityView({ entity, groups, query, collapsedGroups, sortPrefs, onToggleGroup, onSortChange, renderItem, typeEntryMap, onClickNote }: {
|
2026-02-22 10:48:13 +01:00
|
|
|
entity: VaultEntry; groups: RelationshipGroup[]; query: string
|
2026-02-22 12:08:53 +01:00
|
|
|
collapsedGroups: Set<string>; sortPrefs: Record<string, SortConfig>
|
|
|
|
|
onToggleGroup: (label: string) => void; onSortChange: (label: string, opt: SortOption, dir: SortDirection) => void
|
2026-02-22 10:48:13 +01:00
|
|
|
renderItem: (entry: VaultEntry) => React.ReactNode
|
2026-02-23 20:12:54 +01:00
|
|
|
typeEntryMap: Record<string, VaultEntry>; onClickNote: (entry: VaultEntry, e: React.MouseEvent) => void
|
2026-02-22 10:48:13 +01:00
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="h-full overflow-y-auto">
|
2026-02-26 20:50:29 +01:00
|
|
|
<PinnedCard entry={entity} typeEntryMap={typeEntryMap} onClickNote={onClickNote} />
|
2026-02-22 10:48:13 +01:00
|
|
|
{groups.length === 0
|
|
|
|
|
? <EmptyMessage text={query ? 'No matching items' : 'No related items'} />
|
|
|
|
|
: groups.map((group) => (
|
|
|
|
|
<RelationshipGroupSection key={group.label} group={group} isCollapsed={collapsedGroups.has(group.label)} sortPrefs={sortPrefs} onToggle={() => onToggleGroup(group.label)} handleSortChange={onSortChange} renderItem={renderItem} />
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-02-15 12:56:28 +01:00
|
|
|
|
2026-02-23 21:11:41 +01:00
|
|
|
function ListViewHeader({ typeDocument, isTrashView, expiredTrashCount, typeEntryMap, onClickNote }: {
|
|
|
|
|
typeDocument: VaultEntry | null; isTrashView: boolean; expiredTrashCount: number
|
|
|
|
|
typeEntryMap: Record<string, VaultEntry>; onClickNote: (entry: VaultEntry, e: React.MouseEvent) => void
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{typeDocument && <PinnedCard entry={typeDocument} typeEntryMap={typeEntryMap} onClickNote={onClickNote} />}
|
|
|
|
|
<TrashWarningBanner expiredCount={isTrashView ? expiredTrashCount : 0} />
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 14:42:06 +01:00
|
|
|
function ListView({ typeDocument, isTrashView, isChangesView, expiredTrashCount, searched, query, renderItem, typeEntryMap, onClickNote }: {
|
|
|
|
|
typeDocument: VaultEntry | null; isTrashView: boolean; isChangesView?: boolean; expiredTrashCount: number
|
2026-02-22 10:48:13 +01:00
|
|
|
searched: VaultEntry[]; query: string
|
|
|
|
|
renderItem: (entry: VaultEntry) => React.ReactNode
|
2026-02-23 20:12:54 +01:00
|
|
|
typeEntryMap: Record<string, VaultEntry>; onClickNote: (entry: VaultEntry, e: React.MouseEvent) => void
|
2026-02-22 10:48:13 +01:00
|
|
|
}) {
|
2026-02-24 14:42:06 +01:00
|
|
|
const emptyText = isChangesView ? 'No pending changes' : isTrashView ? 'Trash is empty' : (query ? 'No matching notes' : 'No notes found')
|
2026-02-23 21:11:41 +01:00
|
|
|
const hasHeader = typeDocument || (isTrashView && expiredTrashCount > 0)
|
|
|
|
|
|
|
|
|
|
if (searched.length === 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="h-full overflow-y-auto">
|
|
|
|
|
{hasHeader && <ListViewHeader typeDocument={typeDocument} isTrashView={isTrashView} expiredTrashCount={expiredTrashCount} typeEntryMap={typeEntryMap} onClickNote={onClickNote} />}
|
|
|
|
|
<EmptyMessage text={emptyText} />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
return (
|
2026-02-23 21:11:41 +01:00
|
|
|
<Virtuoso
|
|
|
|
|
style={{ height: '100%' }}
|
|
|
|
|
data={searched}
|
|
|
|
|
overscan={200}
|
|
|
|
|
components={{
|
|
|
|
|
Header: hasHeader ? () => <ListViewHeader typeDocument={typeDocument} isTrashView={isTrashView} expiredTrashCount={expiredTrashCount} typeEntryMap={typeEntryMap} onClickNote={onClickNote} /> : undefined,
|
|
|
|
|
}}
|
|
|
|
|
itemContent={(_index, entry) => renderItem(entry)}
|
|
|
|
|
/>
|
2026-02-22 10:48:13 +01:00
|
|
|
)
|
|
|
|
|
}
|
2026-02-21 17:09:29 +01:00
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
// --- Pure helpers ---
|
feat: implement context view in NoteList
When a note is selected from the sidebar (entity selection), NoteList
now shows a context view instead of a flat list:
- Prominent top card with type-colored background, bold title, snippet,
timestamp, and type icon
- Grouped relationship sections (Children, Events, Referenced By,
Belongs To, Related To, Backlinks) with collapse/expand chevrons
- Backlinks detected by scanning allContent for wikilink references
- Groups show ALL-CAPS headers with count and CaretDown/CaretRight toggle
- Normal flat list shown when sidebar selection is "All Notes"
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 18:47:38 +01:00
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
function filterByQuery<T extends { title: string }>(items: T[], query: string): T[] {
|
|
|
|
|
return query ? items.filter((e) => e.title.toLowerCase().includes(query)) : items
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function filterGroupsByQuery(groups: RelationshipGroup[], query: string): RelationshipGroup[] {
|
|
|
|
|
if (!query) return groups
|
|
|
|
|
return groups.map((g) => ({ ...g, entries: filterByQuery(g.entries, query) })).filter((g) => g.entries.length > 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function countExpiredTrash(entries: VaultEntry[]): number {
|
|
|
|
|
const now = Date.now() / 1000
|
|
|
|
|
return entries.filter((e) => e.trashedAt && (now - e.trashedAt) >= 86400 * 30).length
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 20:12:54 +01:00
|
|
|
// --- Click routing ---
|
|
|
|
|
|
|
|
|
|
function routeNoteClick(
|
|
|
|
|
entry: VaultEntry, e: React.MouseEvent,
|
|
|
|
|
onSelectNote: (entry: VaultEntry) => void,
|
|
|
|
|
onReplaceActiveTab: (entry: VaultEntry) => void,
|
|
|
|
|
) {
|
|
|
|
|
if (e.metaKey || e.ctrlKey) { onSelectNote(entry) } else { onReplaceActiveTab(entry) }
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
// --- Data hooks ---
|
|
|
|
|
|
|
|
|
|
interface NoteListDataParams {
|
|
|
|
|
entries: VaultEntry[]; selection: SidebarSelection; allContent: Record<string, string>
|
2026-02-23 21:55:57 +01:00
|
|
|
query: string; listSort: SortOption; listDirection: SortDirection
|
2026-02-24 14:42:06 +01:00
|
|
|
modifiedPathSet: Set<string>
|
2026-02-22 10:48:13 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 14:42:06 +01:00
|
|
|
function useNoteListData({ entries, selection, allContent, query, listSort, listDirection, modifiedPathSet }: NoteListDataParams) {
|
2026-02-22 10:48:13 +01:00
|
|
|
const isEntityView = selection.kind === 'entity'
|
|
|
|
|
const isTrashView = selection.kind === 'filter' && selection.filter === 'trash'
|
2026-02-24 14:42:06 +01:00
|
|
|
const isChangesView = selection.kind === 'filter' && selection.filter === 'changes'
|
2026-02-21 13:27:33 +01:00
|
|
|
|
2026-02-20 21:47:42 +01:00
|
|
|
const typeDocument = useMemo(() => {
|
2026-02-22 10:18:05 +01:00
|
|
|
if (selection.kind !== 'sectionGroup') return null
|
|
|
|
|
return entries.find((e) => e.isA === 'Type' && e.title === selection.type) ?? null
|
|
|
|
|
}, [selection, entries])
|
2026-02-15 10:30:13 +01:00
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
const searched = useMemo(() => {
|
|
|
|
|
if (isEntityView) return []
|
2026-02-24 14:42:06 +01:00
|
|
|
if (isChangesView) {
|
|
|
|
|
const sorted = [...entries.filter((e) => modifiedPathSet.has(e.path))].sort(getSortComparator(listSort, listDirection))
|
|
|
|
|
return filterByQuery(sorted, query)
|
|
|
|
|
}
|
2026-02-23 12:01:46 +01:00
|
|
|
const sorted = [...filterEntries(entries, selection)].sort(getSortComparator(listSort, listDirection))
|
2026-02-22 10:48:13 +01:00
|
|
|
return filterByQuery(sorted, query)
|
2026-02-24 14:42:06 +01:00
|
|
|
}, [entries, selection, isEntityView, isChangesView, listSort, listDirection, query, modifiedPathSet])
|
2026-02-17 17:14:36 +01:00
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
const searchedGroups = useMemo(() => {
|
|
|
|
|
if (!isEntityView) return []
|
|
|
|
|
const groups = buildRelationshipGroups(selection.entry, entries, allContent)
|
2026-02-22 10:48:13 +01:00
|
|
|
return filterGroupsByQuery(groups, query)
|
2026-02-22 10:18:05 +01:00
|
|
|
}, [isEntityView, selection, entries, allContent, query])
|
2026-02-14 19:48:59 +01:00
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
const expiredTrashCount = useMemo(
|
|
|
|
|
() => isTrashView ? countExpiredTrash(searched) : 0,
|
|
|
|
|
[isTrashView, searched],
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-24 14:42:06 +01:00
|
|
|
return { isEntityView, isTrashView, isChangesView, typeDocument, searched, searchedGroups, expiredTrashCount }
|
2026-02-22 10:48:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Main component ---
|
|
|
|
|
|
2026-02-24 15:54:24 +01:00
|
|
|
const defaultGetNoteStatus = (): NoteStatus => 'clean'
|
|
|
|
|
|
2026-02-24 16:35:47 +01:00
|
|
|
function NoteListInner({ entries, selection, selectedNote, allContent, modifiedFiles, getNoteStatus, onSelectNote, onReplaceActiveTab, onCreateNote }: NoteListProps) {
|
2026-02-22 10:48:13 +01:00
|
|
|
const [search, setSearch] = useState('')
|
|
|
|
|
const [searchVisible, setSearchVisible] = useState(false)
|
|
|
|
|
const [collapsedGroups, setCollapsedGroups] = useState<Set<string>>(new Set())
|
2026-02-22 12:08:53 +01:00
|
|
|
const [sortPrefs, setSortPrefs] = useState<Record<string, SortConfig>>(loadSortPreferences)
|
2026-02-25 21:43:16 +01:00
|
|
|
const { onMouseDown: onDragMouseDown } = useDragRegion()
|
2026-02-22 10:48:13 +01:00
|
|
|
|
2026-02-24 16:35:47 +01:00
|
|
|
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])
|
|
|
|
|
|
2026-02-22 12:08:53 +01:00
|
|
|
const handleSortChange = useCallback((groupLabel: string, option: SortOption, direction: SortDirection) => {
|
|
|
|
|
setSortPrefs((prev) => { const next = { ...prev, [groupLabel]: { option, direction } }; saveSortPreferences(next); return next })
|
2026-02-22 10:48:13 +01:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
const toggleGroup = useCallback((label: string) => {
|
2026-02-23 08:53:43 +01:00
|
|
|
setCollapsedGroups((prev) => { const next = new Set(prev); if (next.has(label)) { next.delete(label) } else { next.add(label) }; return next })
|
2026-02-22 10:48:13 +01:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
const typeEntryMap = useTypeEntryMap(entries)
|
|
|
|
|
const query = search.trim().toLowerCase()
|
2026-02-22 12:08:53 +01:00
|
|
|
const listConfig = sortPrefs['__list__'] ?? { option: 'modified' as SortOption, direction: 'desc' as SortDirection }
|
|
|
|
|
const listSort = listConfig.option
|
|
|
|
|
const listDirection = listConfig.direction
|
2026-02-24 14:42:06 +01:00
|
|
|
const { isEntityView, isTrashView, isChangesView, typeDocument, searched, searchedGroups, expiredTrashCount } = useNoteListData({ entries, selection, allContent, query, listSort, listDirection, modifiedPathSet })
|
2026-02-21 16:54:59 +01:00
|
|
|
|
2026-02-23 20:12:54 +01:00
|
|
|
const handleClickNote = useCallback((entry: VaultEntry, e: React.MouseEvent) => {
|
|
|
|
|
routeNoteClick(entry, e, onSelectNote, onReplaceActiveTab)
|
|
|
|
|
}, [onSelectNote, onReplaceActiveTab])
|
|
|
|
|
|
2026-02-22 10:18:05 +01:00
|
|
|
const renderItem = useCallback((entry: VaultEntry) => (
|
2026-02-24 16:35:47 +01:00
|
|
|
<NoteItem key={entry.path} entry={entry} isSelected={selectedNote?.path === entry.path} noteStatus={resolvedGetNoteStatus(entry.path)} typeEntryMap={typeEntryMap} onClickNote={handleClickNote} />
|
|
|
|
|
), [selectedNote?.path, handleClickNote, typeEntryMap, resolvedGetNoteStatus])
|
2026-02-20 21:47:42 +01:00
|
|
|
|
2026-02-14 18:22:42 +01:00
|
|
|
return (
|
2026-02-17 17:14:36 +01:00
|
|
|
<div className="flex flex-col overflow-hidden border-r border-border bg-card text-foreground" style={{ height: '100%' }}>
|
2026-02-26 20:14:41 +01:00
|
|
|
<div className="flex h-[52px] shrink-0 items-center justify-between border-b border-border px-4" onMouseDown={onDragMouseDown} style={{ cursor: 'default' }}>
|
2026-02-22 10:18:05 +01:00
|
|
|
<h3 className="m-0 min-w-0 flex-1 truncate text-[14px] font-semibold">{resolveHeaderTitle(selection, typeDocument)}</h3>
|
2026-02-17 11:03:23 +01:00
|
|
|
<div className="flex items-center gap-3" style={{ WebkitAppRegion: 'no-drag' } as React.CSSProperties}>
|
2026-02-22 12:08:53 +01:00
|
|
|
{!isEntityView && <SortDropdown groupLabel="__list__" current={listSort} direction={listDirection} onChange={handleSortChange} />}
|
2026-02-22 10:18:05 +01:00
|
|
|
<button className="flex items-center text-muted-foreground transition-colors hover:text-foreground" onClick={() => { setSearchVisible(!searchVisible); if (searchVisible) setSearch('') }} title="Search notes">
|
2026-02-17 11:03:23 +01:00
|
|
|
<MagnifyingGlass size={16} />
|
|
|
|
|
</button>
|
2026-02-22 11:38:03 +01:00
|
|
|
<button className="flex items-center text-muted-foreground transition-colors hover:text-foreground" onClick={() => onCreateNote()} title="Create new note">
|
2026-02-17 11:03:23 +01:00
|
|
|
<Plus size={16} />
|
|
|
|
|
</button>
|
2026-02-14 21:14:16 +01:00
|
|
|
</div>
|
2026-02-14 19:46:44 +01:00
|
|
|
</div>
|
2026-02-16 16:56:44 +01:00
|
|
|
|
2026-02-17 11:03:23 +01:00
|
|
|
{searchVisible && (
|
|
|
|
|
<div className="border-b border-border px-3 py-2">
|
2026-02-22 10:18:05 +01:00
|
|
|
<Input placeholder="Search notes..." value={search} onChange={(e) => setSearch(e.target.value)} className="h-8 text-[13px]" autoFocus />
|
2026-02-17 11:03:23 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-16 16:56:44 +01:00
|
|
|
|
2026-02-17 17:14:36 +01:00
|
|
|
<div className="flex-1 overflow-hidden" style={{ minHeight: 0 }}>
|
2026-02-22 11:00:07 +01:00
|
|
|
{isEntityView && selection.kind === 'entity' ? (
|
2026-02-23 20:12:54 +01:00
|
|
|
<EntityView entity={selection.entry} groups={searchedGroups} query={query} collapsedGroups={collapsedGroups} sortPrefs={sortPrefs} onToggleGroup={toggleGroup} onSortChange={handleSortChange} renderItem={renderItem} typeEntryMap={typeEntryMap} onClickNote={handleClickNote} />
|
2026-02-22 10:18:05 +01:00
|
|
|
) : (
|
2026-02-24 14:42:06 +01:00
|
|
|
<ListView typeDocument={typeDocument} isTrashView={isTrashView} isChangesView={isChangesView} expiredTrashCount={expiredTrashCount} searched={searched} query={query} renderItem={renderItem} typeEntryMap={typeEntryMap} onClickNote={handleClickNote} />
|
2026-02-14 18:22:42 +01:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-02-17 17:14:36 +01:00
|
|
|
|
|
|
|
|
export const NoteList = memo(NoteListInner)
|