MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / QuickNotesView

Function QuickNotesView

packages/app-core/src/components/QuickNotesView.tsx:26–294  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24}
25
26export function QuickNotesView(): JSX.Element {
27 const notes = useStore((s) => s.notes)
28 const selectNote = useStore((s) => s.selectNote)
29 const closeActiveNote = useStore((s) => s.closeActiveNote)
30 const createAndOpen = useStore((s) => s.createAndOpen)
31 const quickNoteDateTitle = useStore((s) => s.quickNoteDateTitle)
32 const quickNoteTitlePrefix = useStore((s) => s.quickNoteTitlePrefix)
33 const keymapOverrides = useStore((s) => s.keymapOverrides)
34 const vimMode = useStore((s) => s.vimMode)
35 const setFocusedPanel = useStore((s) => s.setFocusedPanel)
36 const systemFolderLabels = useStore((s) => s.systemFolderLabels)
37 const amActive = useStore(isQuickNotesViewActive)
38 const quickLabel = getSystemFolderLabel('quick', systemFolderLabels)
39
40 const [filter, setFilter] = useState('')
41 const [cursorIndex, setCursorIndex] = useState(0)
42 const filterRef = useRef<HTMLInputElement>(null)
43 const rootRef = useRef<HTMLDivElement>(null)
44 const gPending = useRef(0)
45 const gTimer = useRef<ReturnType<typeof setTimeout>>()
46
47 const quickNotes = useMemo(
48 () =>
49 notes
50 .filter((note) => note.folder === 'quick')
51 .sort((a, b) => b.updatedAt - a.updatedAt),
52 [notes]
53 )
54
55 const filtered = useMemo(() => {
56 const q = filter.trim().toLowerCase()
57 if (!q) return quickNotes
58 return quickNotes.filter(
59 (note) =>
60 note.title.toLowerCase().includes(q) ||
61 note.excerpt.toLowerCase().includes(q) ||
62 note.path.toLowerCase().includes(q)
63 )
64 }, [quickNotes, filter])
65
66 const safeCursor = Math.min(cursorIndex, Math.max(0, filtered.length - 1))
67 const current = filtered[safeCursor] ?? null
68
69 useEffect(() => {
70 if (safeCursor !== cursorIndex) setCursorIndex(safeCursor)
71 }, [cursorIndex, safeCursor])
72
73 useEffect(() => {
74 if (!current) return
75 const el = rootRef.current?.querySelector<HTMLElement>(
76 `[data-quick-row="${cssEscape(current.path)}"]`
77 )
78 el?.scrollIntoView({ block: 'nearest' })
79 }, [current])
80
81 const openNote = useCallback(
82 async (path: string) => {
83 await selectNote(path)

Callers

nothing calls this directly

Calls 4

getSystemFolderLabelFunction · 0.90
resolveQuickNoteTitleFunction · 0.90
cssEscapeFunction · 0.70
formatDateFunction · 0.70

Tested by

no test coverage detected