import React, { Component } from "react";
import { TPMIndexHOC } from "../modules/tpm/TPMIndexHOC";
import { SnackbarHOC } from "educoder";
import { CNotificationHOC } from "../modules/courses/common/CNotificationHOC";
import { Route, Switch, Redirect } from "react-router-dom";
import Loading from "../Loading";
import Loadable from "react-loadable";
import "./css/Index.css";
import "./css/All.scss";

const Detail = Loadable({
  loader: () => import("./ForumsDetail"),
  loading: Loading,
});
const Theme = Loadable({
  loader: () => import("./Theme"),
  loading: Loading,
});
const Forums = Loadable({
  loader: () => import("./Forums"),
  loading: Loading,
});
const New = Loadable({
  loader: () => import("./New"),
  loading: Loading,
});
class Index extends Component {
  componentDidUpdate=()=>{
    this.props.history.listen(()=>{
      if (document.body.scrollTop || document.documentElement.scrollTop > 0) {
        window.scrollTo(0, 0)
      }
    })
  }
  render() {
    return (
      <div className="newMain">
        <Switch {...this.props}>
          {/* 主题全部 */}
          <Route
            path="/forums/theme/:plateMainId"
            render={(props) => (
              <Theme {...this.props} {...props} />
            )}
          ></Route>
          {/* 详情 */}
          <Route
            path="/forums/:id/detail"
            render={(props) => <Detail {...this.props} {...props} />}
          ></Route>
          <Route
            path="/forums/:forumId/edit"
            render={(props) => <New {...this.props} {...props} />}
          ></Route>
          <Route
            path="/forums/new"
            render={(props) => <New {...this.props} {...props} />}
          ></Route>
          <Route path="/forums" render={(props) => <Forums {...this.props} {...props}/>}></Route>
          <Redirect from="/" to="/forums"/>
          {/* <Route
            exact
            path="/"
            render={(props) => (
              <Forums {...this.props} {...props}/>
            )}
          ></Route> */}
        </Switch>
      </div>
    );
  }
}
export default CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(Index)));
