diff --git a/src/containers/project-loader.jsx b/src/containers/project-loader.jsx index 7f178b6232416aca90e22d35c36c56af7c53ba92..1055f70cb68c9bcf45f92c8591d2dfc9edbea063 100644 --- a/src/containers/project-loader.jsx +++ b/src/containers/project-loader.jsx @@ -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));