Don't crash the editor when a project file fails to upload.
This commit is contained in:
1 parent
f34db6bd9d
commit
18e5fe7b3f
1 file changed
+19
-12
@@ -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));
|
||||
Reference in new issue
Block a user