Skip to content
Snippets Groups Projects
  • Ray Schamp's avatar
    789fd146
    Layout pass · 789fd146
    Ray Schamp authored
    Move layout styles from component stylesheets to the GUI, or the component that is placing the component.
    
    Add a new `Box` component to control layouts, basically giving a convenient way to lay out with flexbox.
    
    Use `Box` as the output component for any component that may need to be passed layout options. The props passing convention allows giving layout props to the final `Box` component, making wrapping with another `Box` unnecessary in some cases.
    789fd146
    History
    Layout pass
    Ray Schamp authored
    Move layout styles from component stylesheets to the GUI, or the component that is placing the component.
    
    Add a new `Box` component to control layouts, basically giving a convenient way to lay out with flexbox.
    
    Use `Box` as the output component for any component that may need to be passed layout options. The props passing convention allows giving layout props to the final `Box` component, making wrapping with another `Box` unnecessary in some cases.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
index.jsx 2.21 KiB
const React = require('react');
const ReactDOM = require('react-dom');
const {Provider} = require('react-redux');
const {createStore} = require('redux');

const GUI = require('./containers/gui.jsx');
const log = require('./lib/log');
const ProjectLoader = require('./lib/project-loader');
const reducer = require('./reducers/gui');

const styles = require('./index.css');

class App extends React.Component {
    constructor (props) {
        super(props);
        this.fetchProjectId = this.fetchProjectId.bind(this);
        this.updateProject = this.updateProject.bind(this);
        this.state = {
            projectId: null,
            projectData: JSON.stringify(ProjectLoader.DEFAULT_PROJECT_DATA)
        };
    }
    componentDidMount () {
        window.addEventListener('hashchange', this.updateProject);
        this.updateProject();
    }
    componentWillUnmount () {
        window.removeEventListener('hashchange', this.updateProject);
    }
    fetchProjectId () {
        return window.location.hash.substring(1);
    }
    updateProject () {
        const projectId = this.fetchProjectId();
        if (projectId !== this.state.projectId) {
            if (projectId.length < 1) {
                return this.setState({
                    projectId: projectId,
                    projectData: JSON.stringify(ProjectLoader.DEFAULT_PROJECT_DATA)
                });
            }
            ProjectLoader.load(projectId, (err, body) => {
                if (err) return log.error(err);
                this.setState({projectData: body});
            });
            this.setState({projectId: projectId});
        }
    }
    render () {
        return (
            <GUI
                basePath={this.props.basePath}
                projectData={this.state.projectData}
            />
        );
    }
}

App.propTypes = {
    basePath: React.PropTypes.string
};

const appTarget = document.createElement('div');
appTarget.className = styles.app;
document.body.appendChild(appTarget);
const store = createStore(
    reducer,
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
ReactDOM.render((
    <Provider store={store}>
        <App basePath={process.env.BASE_PATH} />
    </Provider>
), appTarget);