Import: better handle rejected files.

master
Tom Hacohen 2020-01-20 17:17:35 +02:00
parent d8a0aa19ca
commit 8567dd70b7
1 changed files with 10 additions and 5 deletions

View File

@ -102,7 +102,7 @@ class ImportDialog extends React.Component<PropsType> {
);
}
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<PropsType> {
}
};
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[]) {