From 8567dd70b79b7e52a7e80c7e9f7df22ffb16eade Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 20 Jan 2020 17:17:35 +0200 Subject: [PATCH] Import: better handle rejected files. --- src/Journals/ImportDialog.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Journals/ImportDialog.tsx b/src/Journals/ImportDialog.tsx index f97c0e4..de2104a 100644 --- a/src/Journals/ImportDialog.tsx +++ b/src/Journals/ImportDialog.tsx @@ -102,7 +102,7 @@ class ImportDialog extends React.Component { ); } - private onFileDropCommon(itemsCreator: (fileText: string) => PimType[], acceptedFiles: File[], _rejectedFiles: File[]) { + private onFileDropCommon(itemsCreator: (fileText: string) => PimType[], acceptedFiles: File[], rejectedFiles: File[]) { // XXX: implement handling of rejectedFiles const reader = new FileReader(); @@ -155,10 +155,15 @@ class ImportDialog extends React.Component { } }; - this.setState({ loading: true }); - acceptedFiles.forEach((file) => { - reader.readAsText(file); - }); + if (acceptedFiles.length > 0) { + this.setState({ loading: true }); + acceptedFiles.forEach((file) => { + reader.readAsText(file); + }); + } else { + alert('Failed importing file. Is the file type supported?'); + console.log('Failed importing files. Rejected:', rejectedFiles); + } } private onFileDropContact(acceptedFiles: File[], rejectedFiles: File[]) {