From 461f286f53e992a936968fa577230febb554ca0b Mon Sep 17 00:00:00 2001 From: seavan Date: Fri, 4 Jan 2019 18:21:08 -0500 Subject: [PATCH] fix: deleting inline file should delete file in the list as well [ch18037] (#412) --- app/components/files/file-state.js | 11 ++++++++++- app/components/files/file-upload-action-sheet.js | 7 ++++++- app/components/helpers/imagepicker.ts | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/components/files/file-state.js b/app/components/files/file-state.js index b5b0825cf..bd314192e 100644 --- a/app/components/files/file-state.js +++ b/app/components/files/file-state.js @@ -61,7 +61,16 @@ class FileState extends RoutedState { } @action - async deleteFile(file) { + async deleteFile(fileInfo) { + const id = fileInfo.fileId; + let file = fileStore.getById(id); + if (!file) { + file = await fileStore.loadKegByFileId(id); + if (!file) { + console.error(`could not resolve a file ${id}`); + return Promise.resolve(); + } + } const isOwner = file.owner === User.current.username; const title = isOwner ? tx('dialog_confirmDeleteFile') : tx('title_confirmRemoveFile'); let subtitle = ''; diff --git a/app/components/files/file-upload-action-sheet.js b/app/components/files/file-upload-action-sheet.js index 30980365a..77369c0f5 100644 --- a/app/components/files/file-upload-action-sheet.js +++ b/app/components/files/file-upload-action-sheet.js @@ -11,7 +11,12 @@ import ActionSheetLayout from '../layout/action-sheet-layout'; async function doUpload(sourceFunction, inline) { const uploader = inline ? fileState.uploadInline : fileState.uploadInFiles; - const source = observable(await sourceFunction()); + const uploadInfo = await sourceFunction(); + if (!uploadInfo) { + console.log(`no upload info provided. skipping upload`); + return; + } + const source = observable(uploadInfo); if (inline) { const userSelection = await FileSharePreview.popup(source.url, source.fileName); if (!userSelection) return; diff --git a/app/components/helpers/imagepicker.ts b/app/components/helpers/imagepicker.ts index e2bf16425..8e35bdad7 100644 --- a/app/components/helpers/imagepicker.ts +++ b/app/components/helpers/imagepicker.ts @@ -55,6 +55,10 @@ async function processResponse(functor, params?) { if (!response.path && response.uri) { response.path = response.uri; } + if (!response.path) { + console.log(`user cancelled image selection. no path returned`); + return null; + } // if it's a HEIF or HEIC file, it would still give you path to JPG asset // for the sake of compatibility const ext = fileHelpers