feat: show deleted notes as restorable changes
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { useState, useCallback, useEffect, useRef } from 'react'
|
||||
import type { VirtuosoHandle } from 'react-virtuoso'
|
||||
import type { VaultEntry } from '../types'
|
||||
import { prefetchNoteContent } from './useTabManagement'
|
||||
|
||||
interface NoteListKeyboardOptions {
|
||||
items: VaultEntry[]
|
||||
selectedNotePath: string | null
|
||||
onOpen: (entry: VaultEntry) => void
|
||||
onPrefetch?: (entry: VaultEntry) => void
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
export function useNoteListKeyboard({
|
||||
items, selectedNotePath, onOpen, enabled,
|
||||
items, selectedNotePath, onOpen, onPrefetch, enabled,
|
||||
}: NoteListKeyboardOptions) {
|
||||
const [highlightedIndex, setHighlightedIndex] = useState(-1)
|
||||
const virtuosoRef = useRef<VirtuosoHandle>(null)
|
||||
@@ -30,7 +30,7 @@ export function useNoteListKeyboard({
|
||||
setHighlightedIndex(prev => {
|
||||
const next = Math.min((prev < 0 ? -1 : prev) + 1, items.length - 1)
|
||||
virtuosoRef.current?.scrollToIndex({ index: next, behavior: 'auto' })
|
||||
if (next >= 0 && next < items.length) prefetchNoteContent(items[next].path)
|
||||
if (next >= 0 && next < items.length) onPrefetch?.(items[next])
|
||||
return next
|
||||
})
|
||||
} else if (e.key === 'ArrowUp') {
|
||||
@@ -38,14 +38,14 @@ export function useNoteListKeyboard({
|
||||
setHighlightedIndex(prev => {
|
||||
const next = Math.max((prev < 0 ? items.length : prev) - 1, 0)
|
||||
virtuosoRef.current?.scrollToIndex({ index: next, behavior: 'auto' })
|
||||
if (next >= 0 && next < items.length) prefetchNoteContent(items[next].path)
|
||||
if (next >= 0 && next < items.length) onPrefetch?.(items[next])
|
||||
return next
|
||||
})
|
||||
} else if (e.key === 'Enter' && highlightedIndex >= 0 && highlightedIndex < items.length) {
|
||||
e.preventDefault()
|
||||
onOpen(items[highlightedIndex])
|
||||
}
|
||||
}, [enabled, items, highlightedIndex, onOpen])
|
||||
}, [enabled, items, highlightedIndex, onOpen, onPrefetch])
|
||||
|
||||
const handleFocus = useCallback(() => {
|
||||
if (highlightedIndex >= 0 || items.length === 0) return
|
||||
|
||||
Reference in New Issue
Block a user