import React, { Component } from "react"; import { Route, Switch, withRouter } from "react-router-dom"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { bindActionCreators } from "redux"; import { actionCreators as volumeActionCreators } from "ducks/volume"; import { actionCreators as sessionActionCreators } from "ducks/session"; import { translate } from "react-i18next"; import Navbar from "components/Global/Navbar"; import config from "config"; import AuthRoute from "components/AuthRoute"; import io from "./io"; import { asyncComponent } from "react-async-component"; @connect(null, (dispatch) => ({ onVolumeLoudnessChange: bindActionCreators(volumeActionCreators.changeVolumeLoudness, dispatch), onVolumeMute: bindActionCreators(volumeActionCreators.muteVolume, dispatch), onVolumeUnmute: bindActionCreators(volumeActionCreators.unmuteVolume, dispatch), onLogin: bindActionCreators(sessionActionCreators.login, dispatch), onBanned: bindActionCreators(sessionActionCreators.banned, dispatch), })) @translate(["pages"], { wait: false }) class App extends Component { // eslint-disable-line react/no-multi-comp static propTypes = { dispatch: PropTypes.func, t: PropTypes.func, }; static defaultProps = { dispatch: () => {}, t: () => {}, }; componentDidMount() { const { dispatch } = this.props; io.init(config.serverDomain); io.getSocket(socket => { socket.on("ready", (loggedIn, role, username, userId) => { this.props.onLogin(loggedIn, userId, username, role); }); socket.on("keep.event:banned", reason => this.props.banned(reason)); socket.on("keep.event:user.session.removed", () => { location.reload(); // TODO Give user prompt they've been logged out and let them continue. }); }); if (localStorage.getItem("github_redirect")) { // TODO localStorage.removeItem("github_redirect"); } let volume = parseFloat(localStorage.getItem("volume")); let muted = (localStorage.getItem("muted")); volume = (typeof volume === "number" && !isNaN(volume)) ? volume : 20; localStorage.setItem("volume", volume); this.props.onVolumeLoudnessChange(volume); muted ? this.props.onVolumeMute() : this.props.onVolumeUnmute(); } render() { const { t } = this.props; return (
System.import("views/Auth/Login"), name: "Login" })} auth="disallowed" title={ t("pages:login") } /> System.import("views/Auth/Logout"), name: "Logout" })} auth="required" title="Logout" /> System.import("views/Auth/Register"), name: "Register" })} auth="disallowed" title={ t("pages:register") } /> System.import("views/Auth/Settings"), name: "Settings" })} auth="required" title={ t("pages:settings") } /> System.import("views/Auth/Settings/SetPassword"), name: "SetPassword" })} auth="required" title={ t("pages:setPassword") } /> System.import("views/Auth/ForgotPassword"), name: "ForgotPassword" })} auth="disallowed" title={ t("pages:resetPassword") } /> System.import("views/Terms"), name: "Terms" })} auth="ignored" title={ t("pages:terms") } /> System.import("views/Privacy"), name: "Privacy" })} auth="ignored" title={ t("pages:privacy") } /> System.import("views/Team"), name: "Team" })} auth="ignored" title={ t("pages:team") } /> System.import("views/Profile"), name: "Profile" })} auth="ignored" /> System.import("views/Station"), name: "Station", })} auth="station" title="TODO" /> System.import("views/Station"), name: "Station", })} auth="station" title="TODO" /> System.import("views/Home"), name: "Home", })} auth="ignored" title={ t("pages:homepage") } /> System.import("views/Errors/Error404"), name: "Error404", })} auth="ignored" title={ t("pages:error404") } />
); } } export default withRouter(App);