Import Dialog: log potential import errors to console and close dialog.

master
Tom Hacohen 5 years ago
parent 3ef5c0c5e2
commit 0dffd71276

@ -108,32 +108,42 @@ class ImportDialog extends React.Component<PropsType> {
reader.onabort = () => alert('file reading was aborted'); reader.onabort = () => alert('file reading was aborted');
reader.onerror = () => alert('file reading has failed'); reader.onerror = () => alert('file reading has failed');
reader.onload = () => { reader.onload = () => {
const fileText = reader.result as string; try {
const items = itemsCreator(fileText); const fileText = reader.result as string;
const items = itemsCreator(fileText);
const { syncJournal } = this.props;
const last = syncJournal.journalEntries.last() as EteSync.Entry; const { syncJournal } = this.props;
const lastUid = last ? last.uid : null; const last = syncJournal.journalEntries.last() as EteSync.Entry;
const lastUid = last ? last.uid : null;
// XXX implement chunked push most likely...
let prevUid = lastUid; // XXX implement chunked push most likely...
const journalItems = items.map((item) => { let prevUid = lastUid;
const ret = createJournalEntry( const journalItems = items.map((item) => {
this.props.etesync, this.props.userInfo, syncJournal.journal, const ret = createJournalEntry(
prevUid, EteSync.SyncEntryAction.Add, item.toIcal()); this.props.etesync, this.props.userInfo, syncJournal.journal,
prevUid, EteSync.SyncEntryAction.Add, item.toIcal());
prevUid = ret.uid;
return ret; prevUid = ret.uid;
}); return ret;
});
store.dispatch<any>(
addEntries(this.props.etesync, syncJournal.journal.uid, journalItems, lastUid) store.dispatch<any>(
).then(() => { addEntries(this.props.etesync, syncJournal.journal.uid, journalItems, lastUid)
).then(() => {
if (this.props.onClose) {
this.setState({ loading: false });
this.props.onClose();
}
});
} catch (e) {
console.error(e);
alert('An error has occurred, please contact developers.');
if (this.props.onClose) { if (this.props.onClose) {
this.setState({ loading: false }); this.setState({ loading: false });
this.props.onClose(); this.props.onClose();
} }
}); throw e;
}
}; };
this.setState({ loading: true }); this.setState({ loading: true });

Loading…
Cancel
Save