import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants' import { WebApplication } from '@/UIModels/Application' import { AppState } from '@/UIModels/AppState' import { FileItem } from '@standardnotes/snjs' import { FilesIllustration } from '@standardnotes/icons' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { StateUpdater, useRef, useState } from 'preact/hooks' import { Button } from '@/Components/Button/Button' import { Icon } from '@/Components/Icon' import { PopoverFileItem } from './PopoverFileItem' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' import { PopoverTabs } from './PopoverTabs' type Props = { application: WebApplication appState: AppState allFiles: FileItem[] attachedFiles: FileItem[] closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void currentTab: PopoverTabs handleFileAction: (action: PopoverFileItemAction) => Promise isDraggingFiles: boolean setCurrentTab: StateUpdater } export const AttachedFilesPopover: FunctionComponent = observer( ({ application, appState, allFiles, attachedFiles, closeOnBlur, currentTab, handleFileAction, isDraggingFiles, setCurrentTab, }) => { const [searchQuery, setSearchQuery] = useState('') const searchInputRef = useRef(null) const filesList = currentTab === PopoverTabs.AttachedFiles ? attachedFiles : allFiles const filteredList = searchQuery.length > 0 ? filesList.filter((file) => file.name.toLowerCase().indexOf(searchQuery.toLowerCase()) !== -1) : filesList const handleAttachFilesClick = async () => { const uploadedFiles = await appState.files.uploadNewFile() if (!uploadedFiles) { return } if (currentTab === PopoverTabs.AttachedFiles) { uploadedFiles.forEach((file) => { handleFileAction({ type: PopoverFileItemActionType.AttachFileToNote, payload: file, }).catch(console.error) }) } } return (
{filteredList.length > 0 || searchQuery.length > 0 ? (
{ setSearchQuery((e.target as HTMLInputElement).value) }} onBlur={closeOnBlur} ref={searchInputRef} /> {searchQuery.length > 0 && ( )}
) : null} {filteredList.length > 0 ? ( filteredList.map((file: FileItem) => { return ( ) }) ) : (
{searchQuery.length > 0 ? 'No result found' : currentTab === PopoverTabs.AttachedFiles ? 'No files attached to this note' : 'No files found in this account'}
Or drop your files here
)}
{filteredList.length > 0 && ( )}
) }, )