p5.js-web-editor/client/modules/App/App.jsx

49 lines
1.2 KiB
React
Raw Normal View History

import PropTypes from 'prop-types';
import React from 'react';
2016-05-18 17:37:59 +00:00
import { connect } from 'react-redux';
2016-06-22 22:36:04 +00:00
import DevTools from './components/DevTools';
import { setPreviousPath } from '../IDE/actions/ide';
2016-05-18 17:37:59 +00:00
const __process = (typeof global !== 'undefined' ? global : window).process;
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
document.body.className = 'light';
2016-05-18 17:37:59 +00:00
}
componentWillReceiveProps(nextProps) {
if (nextProps.location !== this.props.location) {
this.props.setPreviousPath(this.props.location.pathname);
}
}
2016-05-18 17:37:59 +00:00
render() {
return (
2016-09-14 16:46:54 +00:00
<div className="app">
{this.state.isMounted && !window.devToolsExtension && __process.env.NODE_ENV === 'development' && <DevTools />}
2016-06-23 22:29:55 +00:00
{this.props.children}
2016-05-18 17:37:59 +00:00
</div>
);
}
}
App.propTypes = {
children: PropTypes.element,
location: PropTypes.shape({
pathname: PropTypes.string
}).isRequired,
setPreviousPath: PropTypes.func.isRequired,
};
App.defaultProps = {
children: null
};
export default connect(() => ({}), { setPreviousPath })(App);