Skip to content
Snippets Groups Projects
Commit 18e5fe7b authored by Karishma Chadha's avatar Karishma Chadha
Browse files

Don't crash the editor when a project file fails to upload.

parent f34db6bd
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,10 @@ import bindAll from 'lodash.bindall';
import PropTypes from 'prop-types';
import React from 'react';
import {connect} from 'react-redux';
import {defineMessages, injectIntl, intlShape} from 'react-intl';
import analytics from '../lib/analytics';
import log from '../lib/log';
import {
openLoadingProject,
......@@ -26,6 +28,15 @@ import {
* </MyCoolComponent>
* )}</ProjectLoader>
*/
const messages = defineMessages({
loadError: {
id: 'gui.projectLoader.loadError',
defaultMessage: 'The project file that was selected failed to load.',
description: 'An error that displays when a local project file fails to load.'
}
});
class ProjectLoader extends React.Component {
constructor (props) {
super(props);
......@@ -35,10 +46,6 @@ class ProjectLoader extends React.Component {
'handleChange',
'handleClick'
]);
this.state = {
loadingError: false,
errorMessage: ''
};
}
handleChange (e) {
// Remove the hash if any (without triggering a hash change event or a reload)
......@@ -52,13 +59,16 @@ class ProjectLoader extends React.Component {
action: 'Import Project File',
nonInteraction: true
});
})
.catch(error => {
log.warn(error);
alert(this.props.intl.formatMessage(messages.loadError)); // eslint-disable-line no-alert
})
.finally(() => {
this.props.closeLoadingState();
// Reset the file input after project is loaded
// This is necessary in case the user wants to reload a project
thisFileInput.value = null;
})
.catch(error => {
this.setState({loadingError: true, errorMessage: error});
});
if (thisFileInput.files) { // Don't attempt to load if no file was selected
this.props.openLoadingState();
......@@ -83,10 +93,6 @@ class ProjectLoader extends React.Component {
);
}
render () {
if (this.state.loadingError) {
throw new Error(
`Failed to load project from file: ${this.state.errorMessage}`);
}
const {
/* eslint-disable no-unused-vars */
children,
......@@ -103,6 +109,7 @@ class ProjectLoader extends React.Component {
ProjectLoader.propTypes = {
children: PropTypes.func,
closeLoadingState: PropTypes.func,
intl: intlShape.isRequired,
openLoadingState: PropTypes.func,
vm: PropTypes.shape({
loadProject: PropTypes.func
......@@ -121,4 +128,4 @@ const mapDispatchToProps = dispatch => ({
export default connect(
mapStateToProps,
mapDispatchToProps
)(ProjectLoader);
)(injectIntl(ProjectLoader));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment