import { FileItem } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { FunctionComponent, useCallback } from 'react' import { getFileIconComponent } from '../AttachedFilesPopover/getFileIconComponent' import ListItemConflictIndicator from './ListItemConflictIndicator' import ListItemFlagIcons from './ListItemFlagIcons' import ListItemTags from './ListItemTags' import ListItemMetadata from './ListItemMetadata' import { DisplayableListItemProps } from './Types/DisplayableListItemProps' const FileListItem: FunctionComponent = ({ 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( async (posX: number, posY: number) => { const { didSelect } = await appState.selectedItems.selectItem(item.uuid) if (didSelect) { openFileContextMenu(posX, posY) } }, [appState.selectedItems, item.uuid, 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() void openContextMenu(event.clientX, event.clientY) }} > {!hideIcon ? (
) : (
)}
{item.title}
) } export default observer(FileListItem)