import { WebApplication } from '@/UIModels/Application' import { KeyboardKey } from '@/Services/IOService' import { AppState } from '@/UIModels/AppState' import { UuidString } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { FOCUSABLE_BUT_NOT_TABBABLE, NOTES_LIST_SCROLL_THRESHOLD } from '@/Constants' import { ListableContentItem } from './Types/ListableContentItem' import { ContentListItem } from './ContentListItem' import { useCallback } from 'preact/hooks' type Props = { application: WebApplication appState: AppState items: ListableContentItem[] selectedItems: Record paginate: () => void } export const ContentList: FunctionComponent = observer( ({ application, appState, items, selectedItems, paginate }) => { const { selectPreviousItem, selectNextItem } = appState.contentListView const { hideTags, hideDate, hideNotePreview, hideEditorIcon } = appState.contentListView.webDisplayOptions const { sortBy } = appState.contentListView.displayOptions const onScroll = useCallback( (e: Event) => { const offset = NOTES_LIST_SCROLL_THRESHOLD const element = e.target as HTMLElement if (element.scrollTop + element.offsetHeight >= element.scrollHeight - offset) { paginate() } }, [paginate], ) const onKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === KeyboardKey.Up) { e.preventDefault() selectPreviousItem() } else if (e.key === KeyboardKey.Down) { e.preventDefault() selectNextItem() } }, [selectNextItem, selectPreviousItem], ) return (
{items.map((item) => ( ))}
) }, )