import React, { Component } from "react"; import { Route, Switch, withRouter } from "react-router-dom"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { ban, authenticate } from "actions/app"; import Menu from "components/Global/Menu"; import io from "../../io"; import config from "../../../../config/default"; import AuthRoute from "../Auth/AuthRoute"; const asyncComponent = getComponent => { return class AsyncComponent extends React.Component { static Component = null; state = { Component: AsyncComponent.Component }; componentWillMount() { if (!this.state.Component) { getComponent().then(Component => { // eslint-disable-line no-shadow AsyncComponent.Component = Component; this.setState({ Component }); }); } } render() { const { Component } = this.state; // eslint-disable-line no-shadow if (Component) return ; return null; } }; }; @connect() class App extends Component { // eslint-disable-line react/no-multi-comp static propTypes = { dispatch: PropTypes.func, history: PropTypes.shape({ push: PropTypes.func.isRequired, }).isRequired, } static defaultProps = { dispatch: () => {}, } componentDidMount() { const { dispatch } = this.props; io.init(config.serverDomain); io.getSocket(socket => { socket.on("ready", (loggedIn, role, username, userId) => { dispatch(authenticate({ loggedIn, role, username, userId })); }); socket.on("keep.event:banned", reason => dispatch(ban(reason))); }); if (localStorage.getItem("github_redirect")) { this.props.history.push(localStorage.getItem("github_redirect")); localStorage.removeItem("github_redirect"); } } render() { return (
System.import("views/Auth/Login").then(module => module.default) ) } authRequired={ false } /> System.import("views/Auth/Logout").then(module => module.default) ) } authRequired={ true } /> System.import("views/Auth/Register").then(module => module.default) ) } authRequired={ false } /> System.import("views/Auth/Settings").then(module => module.default) ) } authRequired={ true } /> System.import("views/Template").then(module => module.default) ) } /> System.import("views/Home").then(module => module.default) ) } /> System.import("views/NotFound").then(module => module.default) ) } />
); } } export default withRouter(App);