From 54ae4365a344cc3c6c796a3afb6d3020f5493a6b Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Mon, 15 Aug 2022 18:13:29 +0530 Subject: [PATCH] fix: selecting from "Photo Library" on iOS doesn't upload (#1401) --- .../AttachedFilesPopover.tsx | 44 ++++++++++++++++--- .../ContentListView/ContentListView.tsx | 26 ++++++++++- .../Controllers/FilesController.ts | 2 +- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/packages/web/src/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx b/packages/web/src/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx index 07d1a0b9a..5b268c576 100644 --- a/packages/web/src/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx +++ b/packages/web/src/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx @@ -10,6 +10,7 @@ import PopoverFileItem from './PopoverFileItem' import { PopoverFileItemActionType } from './PopoverFileItemAction' import { PopoverTabs } from './PopoverTabs' import { FilesController } from '@/Controllers/FilesController' +import { StreamingFileReader } from '@standardnotes/filepicker' type Props = { application: WebApplication @@ -32,6 +33,8 @@ const AttachedFilesPopover: FunctionComponent = ({ setCurrentTab, attachedTabDisabled, }) => { + const fileInputRef = useRef(null) + const [searchQuery, setSearchQuery] = useState('') const searchInputRef = useRef(null) @@ -42,13 +45,9 @@ const AttachedFilesPopover: FunctionComponent = ({ ? filesList.filter((file) => file.name.toLowerCase().indexOf(searchQuery.toLowerCase()) !== -1) : filesList - const handleAttachFilesClick = async () => { - const uploadedFiles = await filesController.uploadNewFile() - if (!uploadedFiles) { - return - } + const attachFilesIfRequired = (files: FileItem[]) => { if (currentTab === PopoverTabs.AttachedFiles) { - uploadedFiles.forEach((file) => { + files.forEach((file) => { filesController .handleFileAction({ type: PopoverFileItemActionType.AttachFileToNote, @@ -59,6 +58,19 @@ const AttachedFilesPopover: FunctionComponent = ({ } } + const handleAttachFilesClick = async () => { + if (!StreamingFileReader.available()) { + fileInputRef.current?.click() + return + } + + const uploadedFiles = await filesController.uploadNewFile() + if (!uploadedFiles) { + return + } + attachFilesIfRequired(uploadedFiles) + } + const previewHandler = (file: FileItem) => { filesController .handleFileAction({ @@ -161,6 +173,26 @@ const AttachedFilesPopover: FunctionComponent = ({ )} + { + const files = event.currentTarget.files + + if (!files) { + return + } + + for (const file of files) { + const uploadedFiles = await filesController.uploadNewFile(file) + if (uploadedFiles) { + attachFilesIfRequired(uploadedFiles) + } + } + }} + /> {filteredList.length > 0 && (