You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
354 lines
8.9 KiB
354 lines
8.9 KiB
import React, { Component } from "react"; |
|
import "./App.css"; |
|
import { |
|
BrowserRouter as Router, |
|
Route, |
|
Switch, |
|
Redirect, |
|
} from "react-router-dom"; |
|
import { connect } from "react-redux"; |
|
import { user } from "~/Redux/actions"; |
|
import { userProduct } from "~/Redux/actions"; |
|
import proxy from "./Redux/proxy"; |
|
import Home from "./views/Home/index"; |
|
import Faq from "./views/Faq/index"; |
|
import Contact from "./views/Contact/index"; |
|
import About from "./views/About/index"; |
|
import Products from "./views/Products/index"; |
|
import Product from "./views/Product/index"; |
|
import QR from "./views/QR/index"; |
|
import Auth from "./views/Auth/index"; |
|
import QRScan from "./views/QRScan/index"; |
|
import Activation from "./views/Activation/index"; |
|
import ChatList from "./views/ChatList/index"; |
|
import Chatroom from "./views/ChatRoom/index"; |
|
import Cart from "./views/Cart/index"; |
|
import MyBooks from "./views/MyBooks/index"; |
|
import AR from "./views/AR/index"; |
|
import Download from "./views/Download/index"; |
|
import Support from "./views/Support/index"; |
|
import NewProfile from "./views/NewProfile/index"; |
|
import Blogs from "./views/Blogs/index"; |
|
import Blog from "./views/Blog/index"; |
|
// import Sample from "./views/Sample/index"; |
|
import PDF from "./views/PDF/index"; |
|
import Orders from "./views/Orders"; |
|
// import MyBooks2 from "./views/MyBook2"; |
|
class AppRouter extends Component { |
|
constructor(props) { |
|
super(props); |
|
window.router = this; |
|
this.state = { |
|
cartControll: false, |
|
}; |
|
} |
|
|
|
state = {}; |
|
|
|
componentDidUpdate(prevProps, prevState) { |
|
if (this.props.userProductList > 0) { |
|
if (!this.state.cartControll) { |
|
this.setState({ |
|
cartControll: true, |
|
}); |
|
} |
|
} else { |
|
if (!this.state.cartControll) { |
|
this.setState({ |
|
cartControll: true, |
|
}); |
|
} |
|
} |
|
} |
|
|
|
componentDidMount() { |
|
// if (proxy.status() && this.props.userProductList == null) |
|
// this.props.getUserProductList(); |
|
} |
|
|
|
render() { |
|
const mobile = window.innerWidth < 1000 ? true : false; |
|
let status = proxy.status(); |
|
console.log({ status, s: this.props.profile }); |
|
let home = ( |
|
<Route exact path={"/"}> |
|
{status && status.status === 0 ? ( |
|
<Auth page={"profile"} /> |
|
) : ( |
|
<Home status={status} /> |
|
)} |
|
</Route> |
|
); |
|
|
|
return ( |
|
<Router> |
|
<Switch> |
|
{home} |
|
<Route exact path={"/faq"}> |
|
<Faq /> |
|
</Route> |
|
<Route exact path={"/contact"}> |
|
<Contact /> |
|
</Route> |
|
<Route exact path={"/blogs"}> |
|
<Blogs /> |
|
</Route> |
|
<Route exact path={"/blogs/:id"}> |
|
<Blog /> |
|
</Route> |
|
<Route exact path={"/about"}> |
|
<About /> |
|
</Route> |
|
<Route exact path={"/products"}> |
|
<Products /> |
|
</Route> |
|
<Route exact path="/orders"> |
|
<Orders /> |
|
</Route> |
|
<Route exact path="/mybooks"> |
|
<MyBooks /> |
|
</Route> |
|
{/* <Route path={"/sample"}> |
|
<Sample /> |
|
</Route> */} |
|
<Route path={"/pdf"}> |
|
<PDF /> |
|
</Route> |
|
<Route exact path={"/newProfile"}> |
|
{mobile ? ( |
|
status ? ( |
|
<NewProfile /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : ( |
|
<NewProfile /> |
|
)} |
|
</Route> |
|
<Route exact path={"/support"}> |
|
{mobile ? ( |
|
status ? ( |
|
<Support /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : ( |
|
<Support /> |
|
)} |
|
</Route> |
|
<Route exact path={"/products/digital/:id"}> |
|
<Product page="digital" /> |
|
</Route> |
|
<Route exact path={"/products/physical/:id"}> |
|
<Product page="physical" /> |
|
</Route> |
|
<Route exact path={"/qr"}> |
|
<QR /> |
|
</Route> |
|
<Route exact path={"/auth"}> |
|
{proxy.status() ? ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) : ( |
|
<Auth /> |
|
)} |
|
</Route> |
|
<Route exact path={"/profile"}> |
|
{mobile ? ( |
|
status ? ( |
|
<Auth page={"profile"} /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : status ? ( |
|
<Auth page={"profile"} /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/qr-scan"}> |
|
{mobile ? ( |
|
status ? ( |
|
<QRScan /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : status ? ( |
|
<QRScan /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/activation"}> |
|
{mobile ? ( |
|
status ? ( |
|
<Activation /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : status ? ( |
|
<Activation /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/chatroom"}> |
|
{mobile ? ( |
|
status ? ( |
|
<ChatList /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : status ? ( |
|
<ChatList /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/cart"}> |
|
{status ? ( |
|
<Cart /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
{/* <Route exact path={"/mybooks"}> |
|
{mobile ? ( |
|
status ? ( |
|
<MyBooks /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : status ? ( |
|
<MyBooks /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> */} |
|
<Route exact path={"/ar"}> |
|
{mobile ? ( |
|
status ? ( |
|
<AR /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : status ? ( |
|
<AR /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/download"}> |
|
<Download /> |
|
</Route> |
|
<Route exact path={"/chatroom/:id"}> |
|
{mobile ? ( |
|
status ? ( |
|
<Chatroom /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/", |
|
}} |
|
/> |
|
) |
|
) : status ? ( |
|
<Chatroom /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route path={""}> |
|
<Redirect |
|
to={{ |
|
pathname: "/qr", |
|
search: |
|
"?id=" + |
|
window.location.pathname.slice( |
|
window.location.pathname.lastIndexOf("/") + 1, |
|
window.location.pathname.length |
|
), |
|
}} |
|
/> |
|
</Route> |
|
</Switch> |
|
</Router> |
|
); |
|
} |
|
} |
|
|
|
export default connect( |
|
(state) => ({ |
|
profile: state.user.status, |
|
userProductList: state.userProduct.list, |
|
// status: state.user.status, |
|
}), |
|
{ getProfile: user.getProfile, getUserProductList: userProduct.list } |
|
)(AppRouter);
|
|
|