import { FileItem } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { useCallback } from 'preact/hooks' import { getFileIconComponent } from '../AttachedFilesPopover/PopoverFileItem' import { ListItemConflictIndicator } from './ListItemConflictIndicator' import { ListItemFlagIcons } from './ListItemFlagIcons' import { ListItemTags } from './ListItemTags' import { ListItemMetadata } from './ListItemMetadata' import { DisplayableListItemProps } from './Types/DisplayableListItemProps' export const FileListItem: FunctionComponent = observer( ({ application, appState, hideDate, hideIcon, hideTags, item, selected, sortBy, tags }) => { const openFileContextMenu = useCallback( (posX: number, posY: number) => { appState.files.setFileContextMenuLocation({ x: posX, y: posY, }) appState.files.setShowFileContextMenu(true) }, [appState.files], ) const openContextMenu = useCallback( (posX: number, posY: number) => { void appState.contentListView.selectItemWithScrollHandling(item, { userTriggered: true, scrollIntoView: false, }) openFileContextMenu(posX, posY) }, [appState.contentListView, item, openFileContextMenu], ) const onClick = useCallback(() => { void appState.selectedItems.selectItem(item.uuid, true).then(({ didSelect }) => { if (didSelect && appState.selectedItems.selectedItemsCount < 2) { appState.filePreviewModal.activate(item as FileItem, appState.files.allFiles) } }) }, [appState.filePreviewModal, appState.files.allFiles, appState.selectedItems, item]) const IconComponent = () => getFileIconComponent( application.iconsController.getIconForFileType((item as FileItem).mimeType), 'w-5 h-5 flex-shrink-0', ) return (
{ event.preventDefault() openContextMenu(event.clientX, event.clientY) }} > {!hideIcon ? (
) : (
)}
{item.title}
) }, )