2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-05-18 17:37:59 +00:00
|
|
|
import { connect } from 'react-redux';
|
2020-06-08 09:46:38 +00:00
|
|
|
import getConfig from '../../utils/getConfig';
|
2016-06-22 22:36:04 +00:00
|
|
|
import DevTools from './components/DevTools';
|
2016-12-15 23:43:58 +00:00
|
|
|
import { setPreviousPath } from '../IDE/actions/ide';
|
2020-08-17 09:23:58 +00:00
|
|
|
import { setLanguage } from '../IDE/actions/preferences';
|
2016-05-18 17:37:59 +00:00
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
2016-06-23 22:29:55 +00:00
|
|
|
this.state = { isMounted: false };
|
2016-06-22 22:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2016-06-27 21:22:54 +00:00
|
|
|
this.setState({ isMounted: true }); // eslint-disable-line react/no-did-mount-set-state
|
2019-11-25 12:36:08 +00:00
|
|
|
document.body.className = this.props.theme;
|
2016-05-18 17:37:59 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 23:43:58 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2019-08-24 11:28:21 +00:00
|
|
|
const locationWillChange = nextProps.location !== this.props.location;
|
2020-08-11 21:05:44 +00:00
|
|
|
const shouldSkipRemembering =
|
|
|
|
nextProps.location.state &&
|
|
|
|
nextProps.location.state.skipSavingPath === true;
|
2019-08-24 11:28:21 +00:00
|
|
|
|
|
|
|
if (locationWillChange && !shouldSkipRemembering) {
|
2016-12-15 23:43:58 +00:00
|
|
|
this.props.setPreviousPath(this.props.location.pathname);
|
|
|
|
}
|
2020-08-17 09:23:58 +00:00
|
|
|
|
|
|
|
if (this.props.language !== nextProps.language) {
|
|
|
|
this.props.setLanguage(nextProps.language, { persistPreference: false });
|
|
|
|
}
|
2016-12-15 23:43:58 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 12:36:08 +00:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (this.props.theme !== prevProps.theme) {
|
|
|
|
document.body.className = this.props.theme;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 17:37:59 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2016-09-14 16:46:54 +00:00
|
|
|
<div className="app">
|
2020-08-11 21:06:14 +00:00
|
|
|
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
|
2016-06-23 22:29:55 +00:00
|
|
|
{this.props.children}
|
2016-05-18 17:37:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:14:26 +00:00
|
|
|
App.propTypes = {
|
2017-02-22 19:29:35 +00:00
|
|
|
children: PropTypes.element,
|
2016-12-15 23:43:58 +00:00
|
|
|
location: PropTypes.shape({
|
2019-09-08 14:43:16 +00:00
|
|
|
pathname: PropTypes.string,
|
|
|
|
state: PropTypes.shape({
|
|
|
|
skipSavingPath: PropTypes.bool,
|
|
|
|
}),
|
2017-02-22 19:29:35 +00:00
|
|
|
}).isRequired,
|
2016-12-15 23:43:58 +00:00
|
|
|
setPreviousPath: PropTypes.func.isRequired,
|
2020-08-17 09:23:58 +00:00
|
|
|
setLanguage: PropTypes.func.isRequired,
|
|
|
|
language: PropTypes.string,
|
2019-11-25 12:36:08 +00:00
|
|
|
theme: PropTypes.string,
|
2016-06-27 20:14:26 +00:00
|
|
|
};
|
|
|
|
|
2017-02-22 19:29:35 +00:00
|
|
|
App.defaultProps = {
|
2019-11-25 12:36:08 +00:00
|
|
|
children: null,
|
2020-08-17 09:23:58 +00:00
|
|
|
language: null,
|
2019-11-25 12:36:08 +00:00
|
|
|
theme: 'light'
|
2017-02-22 19:29:35 +00:00
|
|
|
};
|
|
|
|
|
2019-11-25 12:36:08 +00:00
|
|
|
const mapStateToProps = state => ({
|
|
|
|
theme: state.preferences.theme,
|
2020-08-17 09:23:58 +00:00
|
|
|
language: state.preferences.language,
|
2019-11-25 12:36:08 +00:00
|
|
|
});
|
|
|
|
|
2020-08-17 09:23:58 +00:00
|
|
|
const mapDispatchToProps = { setPreviousPath, setLanguage };
|
2019-11-25 12:36:08 +00:00
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(App);
|