fix: selecting from "Photo Library" on iOS doesn't upload (#1401)
This commit is contained in:
@@ -10,6 +10,7 @@ import PopoverFileItem from './PopoverFileItem'
|
|||||||
import { PopoverFileItemActionType } from './PopoverFileItemAction'
|
import { PopoverFileItemActionType } from './PopoverFileItemAction'
|
||||||
import { PopoverTabs } from './PopoverTabs'
|
import { PopoverTabs } from './PopoverTabs'
|
||||||
import { FilesController } from '@/Controllers/FilesController'
|
import { FilesController } from '@/Controllers/FilesController'
|
||||||
|
import { StreamingFileReader } from '@standardnotes/filepicker'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -32,6 +33,8 @@ const AttachedFilesPopover: FunctionComponent<Props> = ({
|
|||||||
setCurrentTab,
|
setCurrentTab,
|
||||||
attachedTabDisabled,
|
attachedTabDisabled,
|
||||||
}) => {
|
}) => {
|
||||||
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
@@ -42,13 +45,9 @@ const AttachedFilesPopover: FunctionComponent<Props> = ({
|
|||||||
? filesList.filter((file) => file.name.toLowerCase().indexOf(searchQuery.toLowerCase()) !== -1)
|
? filesList.filter((file) => file.name.toLowerCase().indexOf(searchQuery.toLowerCase()) !== -1)
|
||||||
: filesList
|
: filesList
|
||||||
|
|
||||||
const handleAttachFilesClick = async () => {
|
const attachFilesIfRequired = (files: FileItem[]) => {
|
||||||
const uploadedFiles = await filesController.uploadNewFile()
|
|
||||||
if (!uploadedFiles) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (currentTab === PopoverTabs.AttachedFiles) {
|
if (currentTab === PopoverTabs.AttachedFiles) {
|
||||||
uploadedFiles.forEach((file) => {
|
files.forEach((file) => {
|
||||||
filesController
|
filesController
|
||||||
.handleFileAction({
|
.handleFileAction({
|
||||||
type: PopoverFileItemActionType.AttachFileToNote,
|
type: PopoverFileItemActionType.AttachFileToNote,
|
||||||
@@ -59,6 +58,19 @@ const AttachedFilesPopover: FunctionComponent<Props> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleAttachFilesClick = async () => {
|
||||||
|
if (!StreamingFileReader.available()) {
|
||||||
|
fileInputRef.current?.click()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadedFiles = await filesController.uploadNewFile()
|
||||||
|
if (!uploadedFiles) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
attachFilesIfRequired(uploadedFiles)
|
||||||
|
}
|
||||||
|
|
||||||
const previewHandler = (file: FileItem) => {
|
const previewHandler = (file: FileItem) => {
|
||||||
filesController
|
filesController
|
||||||
.handleFileAction({
|
.handleFileAction({
|
||||||
@@ -161,6 +173,26 @@ const AttachedFilesPopover: FunctionComponent<Props> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
className="absolute top-0 left-0 opacity-0"
|
||||||
|
multiple
|
||||||
|
ref={fileInputRef}
|
||||||
|
onChange={async (event) => {
|
||||||
|
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 && (
|
{filteredList.length > 0 && (
|
||||||
<button
|
<button
|
||||||
className="flex w-full cursor-pointer items-center border-0 border-t border-solid border-border bg-transparent px-3 py-3 text-left text-sm text-text hover:bg-contrast hover:text-foreground focus:bg-info-backdrop focus:shadow-none"
|
className="flex w-full cursor-pointer items-center border-0 border-t border-solid border-border bg-transparent px-3 py-3 text-left text-sm text-text hover:bg-contrast hover:text-foreground focus:bg-info-backdrop focus:shadow-none"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import ContentListHeader from './Header/ContentListHeader'
|
|||||||
import ResponsivePaneContent from '../ResponsivePane/ResponsivePaneContent'
|
import ResponsivePaneContent from '../ResponsivePane/ResponsivePaneContent'
|
||||||
import { AppPaneId } from '../ResponsivePane/AppPaneMetadata'
|
import { AppPaneId } from '../ResponsivePane/AppPaneMetadata'
|
||||||
import { useResponsiveAppPane } from '../ResponsivePane/ResponsivePaneProvider'
|
import { useResponsiveAppPane } from '../ResponsivePane/ResponsivePaneProvider'
|
||||||
|
import { StreamingFileReader } from '@standardnotes/filepicker'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
accountMenuController: AccountMenuController
|
accountMenuController: AccountMenuController
|
||||||
@@ -46,6 +47,7 @@ const ContentListView: FunctionComponent<Props> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { toggleAppPane } = useResponsiveAppPane()
|
const { toggleAppPane } = useResponsiveAppPane()
|
||||||
|
|
||||||
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||||
const itemsViewPanelRef = useRef<HTMLDivElement>(null)
|
const itemsViewPanelRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -68,7 +70,12 @@ const ContentListView: FunctionComponent<Props> = ({
|
|||||||
|
|
||||||
const addNewItem = useCallback(async () => {
|
const addNewItem = useCallback(async () => {
|
||||||
if (isFilesSmartView) {
|
if (isFilesSmartView) {
|
||||||
void filesController.uploadNewFile()
|
if (StreamingFileReader.available()) {
|
||||||
|
void filesController.uploadNewFile()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fileInputRef.current?.click()
|
||||||
} else {
|
} else {
|
||||||
await createNewNote()
|
await createNewNote()
|
||||||
toggleAppPane(AppPaneId.Editor)
|
toggleAppPane(AppPaneId.Editor)
|
||||||
@@ -179,6 +186,23 @@ const ContentListView: FunctionComponent<Props> = ({
|
|||||||
<ResponsivePaneContent paneId={AppPaneId.Items}>
|
<ResponsivePaneContent paneId={AppPaneId.Items}>
|
||||||
<div id="items-title-bar" className="section-title-bar border-b border-solid border-border">
|
<div id="items-title-bar" className="section-title-bar border-b border-solid border-border">
|
||||||
<div id="items-title-bar-container">
|
<div id="items-title-bar-container">
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
className="absolute top-0 left-0 opacity-0"
|
||||||
|
multiple
|
||||||
|
ref={fileInputRef}
|
||||||
|
onChange={(event) => {
|
||||||
|
const files = event.currentTarget.files
|
||||||
|
|
||||||
|
if (!files) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
void filesController.uploadNewFile(file)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<ContentListHeader
|
<ContentListHeader
|
||||||
application={application}
|
application={application}
|
||||||
panelTitle={panelTitle}
|
panelTitle={panelTitle}
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ export class FilesController extends AbstractViewController {
|
|||||||
const selectedFiles =
|
const selectedFiles =
|
||||||
fileOrHandle instanceof File
|
fileOrHandle instanceof File
|
||||||
? [fileOrHandle]
|
? [fileOrHandle]
|
||||||
: StreamingFileReader.available() && fileOrHandle instanceof FileSystemFileHandle
|
: shouldUseStreamingReader && fileOrHandle instanceof FileSystemFileHandle
|
||||||
? await StreamingFileReader.getFilesFromHandles([fileOrHandle])
|
? await StreamingFileReader.getFilesFromHandles([fileOrHandle])
|
||||||
: await picker.selectFiles()
|
: await picker.selectFiles()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user