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'; ...@@ -2,8 +2,10 @@ import bindAll from 'lodash.bindall';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React from 'react'; import React from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {defineMessages, injectIntl, intlShape} from 'react-intl';
import analytics from '../lib/analytics'; import analytics from '../lib/analytics';
import log from '../lib/log';
import { import {
openLoadingProject, openLoadingProject,
...@@ -26,6 +28,15 @@ import { ...@@ -26,6 +28,15 @@ import {
* </MyCoolComponent> * </MyCoolComponent>
* )}</ProjectLoader> * )}</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 { class ProjectLoader extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
...@@ -35,10 +46,6 @@ class ProjectLoader extends React.Component { ...@@ -35,10 +46,6 @@ class ProjectLoader extends React.Component {
'handleChange', 'handleChange',
'handleClick' 'handleClick'
]); ]);
this.state = {
loadingError: false,
errorMessage: ''
};
} }
handleChange (e) { handleChange (e) {
// Remove the hash if any (without triggering a hash change event or a reload) // Remove the hash if any (without triggering a hash change event or a reload)
...@@ -52,13 +59,16 @@ class ProjectLoader extends React.Component { ...@@ -52,13 +59,16 @@ class ProjectLoader extends React.Component {
action: 'Import Project File', action: 'Import Project File',
nonInteraction: true nonInteraction: true
}); });
})
.catch(error => {
log.warn(error);
alert(this.props.intl.formatMessage(messages.loadError)); // eslint-disable-line no-alert
})
.finally(() => {
this.props.closeLoadingState(); this.props.closeLoadingState();
// Reset the file input after project is loaded // Reset the file input after project is loaded
// This is necessary in case the user wants to reload a project // This is necessary in case the user wants to reload a project
thisFileInput.value = null; thisFileInput.value = null;
})
.catch(error => {
this.setState({loadingError: true, errorMessage: error});
}); });
if (thisFileInput.files) { // Don't attempt to load if no file was selected if (thisFileInput.files) { // Don't attempt to load if no file was selected
this.props.openLoadingState(); this.props.openLoadingState();
...@@ -83,10 +93,6 @@ class ProjectLoader extends React.Component { ...@@ -83,10 +93,6 @@ class ProjectLoader extends React.Component {
); );
} }
render () { render () {
if (this.state.loadingError) {
throw new Error(
`Failed to load project from file: ${this.state.errorMessage}`);
}
const { const {
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
children, children,
...@@ -103,6 +109,7 @@ class ProjectLoader extends React.Component { ...@@ -103,6 +109,7 @@ class ProjectLoader extends React.Component {
ProjectLoader.propTypes = { ProjectLoader.propTypes = {
children: PropTypes.func, children: PropTypes.func,
closeLoadingState: PropTypes.func, closeLoadingState: PropTypes.func,
intl: intlShape.isRequired,
openLoadingState: PropTypes.func, openLoadingState: PropTypes.func,
vm: PropTypes.shape({ vm: PropTypes.shape({
loadProject: PropTypes.func loadProject: PropTypes.func
...@@ -121,4 +128,4 @@ const mapDispatchToProps = dispatch => ({ ...@@ -121,4 +128,4 @@ const mapDispatchToProps = dispatch => ({
export default connect( export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps 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