|
| 1 | +import React, { lazy, Suspense, useEffect,useState } from "react"; |
| 2 | +import { Route, Switch, Redirect } from "react-router-dom"; |
| 3 | +import "../node_modules/bootstrap/dist/css/bootstrap.min.css"; |
| 4 | +import { withRouter } from "react-router"; |
| 5 | +import Header from "./components/Header/Header"; |
| 6 | +import Footer from "./components/Footer/Footer"; |
| 7 | +import NotFound from "./pages/404/NotFound"; |
| 8 | +import "./index.scss"; |
| 9 | +import Preloader from "./components/Preloader/Preloader"; |
| 10 | +import Scroll from "./components/Scroll/Scroll"; |
| 11 | +import {authentication} from "./firebase-config" |
| 12 | +import {onAuthStateChanged} from "firebase/auth" |
| 13 | +const Home = lazy(() => import("./pages/Home/Home")); |
| 14 | +const Explore = lazy(() => import("./pages/Explore/Explore")); |
| 15 | +const DetailPage = lazy(() => import("./pages/DetailPage/DetailPage")); |
| 16 | +const ContactUs = lazy(() => import("./pages/ContactUs/ContactUs")); |
| 17 | +const Login = lazy(() => import("./pages/Login/Login")); |
| 18 | +const Forget = lazy(() => import("./pages/ForgetPassword/Forget")); |
| 19 | +const Reset = lazy(() => import("./pages/ResetPassword/Reset")); |
| 20 | +const Report = lazy(() => import("./pages/ReportaBug/Report")); |
| 21 | +const Signup = lazy(() => import("./pages/SignupPage/Signup")); |
| 22 | +const Jobhunt = lazy(() => import("./pages/JobHunt/Jobhunt")); |
| 23 | +function App({ location }) { |
| 24 | + |
| 25 | + const [onUserLogin, setOnUserLogin] = useState(true); |
| 26 | + const [userName, setUserName] = useState(""); |
| 27 | + const [avatar, setAvatar] = useState(""); |
| 28 | + useEffect(()=>{ |
| 29 | + onAuthStateChanged(authentication, (user) => { |
| 30 | + if(user){ |
| 31 | + console.log(user.photoURL) |
| 32 | + setAvatar(user.photoURL); |
| 33 | + setUserName(user.displayName); |
| 34 | + return setOnUserLogin(true); |
| 35 | + } |
| 36 | + setOnUserLogin(false); |
| 37 | + }) |
| 38 | + |
| 39 | + }) |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + if(onUserLogin === true){ |
| 44 | + return ( |
| 45 | + <Suspense fallback={<Preloader />}> |
| 46 | + {location.pathname !== "/404" && ( |
| 47 | + <Header onUserLogin={onUserLogin} userName = {userName} avatar={avatar} currentRoute={location.pathname} /> |
| 48 | + )} |
| 49 | + <Scroll showBelow={200} /> |
| 50 | + <Switch> |
| 51 | + <Route path="/" exact component={Home} /> |
| 52 | + <Route path="/contact" exact component={ContactUs} /> |
| 53 | + <Route path="/explore" exact component={Explore} /> |
| 54 | + <Route path="/jobhunt" exact component={Jobhunt} /> |
| 55 | + <Route path="/e/:slug" exact component={DetailPage} /> |
| 56 | + <Route path="/jobs" exact component={ContactUs} /> |
| 57 | + <Route path="/feed" exact component={ContactUs} /> |
| 58 | + <Route path="/signup" exact component={Signup} /> |
| 59 | + <Route path="/forget" component={Forget} /> |
| 60 | + <Route path="/reset" component={Reset} /> |
| 61 | + <Route path="/report" component={Report} /> |
| 62 | + <Route path="/404" exact component={NotFound} /> |
| 63 | + |
| 64 | + <Redirect to="/" /> |
| 65 | + </Switch> |
| 66 | + {location.pathname !== "/404" && <Footer fill={"#0D1017"} />} |
| 67 | + </Suspense> |
| 68 | + ); |
| 69 | + }else{ |
| 70 | + return ( |
| 71 | + <Suspense fallback={<Preloader />}> |
| 72 | + {location.pathname !== "/404" && ( |
| 73 | + <Header onUserLogin={onUserLogin} userName = {userName} avatar={avatar} currentRoute={location.pathname} /> |
| 74 | + )} |
| 75 | + <Scroll showBelow={200} /> |
| 76 | + <Switch> |
| 77 | + <Route path="/" exact component={Home} /> |
| 78 | + <Route path="/contact" exact component={ContactUs} /> |
| 79 | + <Route path="/explore" exact component={Explore} /> |
| 80 | + <Route path="/jobhunt" exact component={Jobhunt} /> |
| 81 | + <Route path="/e/:slug" exact component={DetailPage} /> |
| 82 | + <Route path="/jobs" exact component={ContactUs} /> |
| 83 | + <Route path="/feed" exact component={ContactUs} /> |
| 84 | + <Route path="/signin" exact component={Login} /> |
| 85 | + <Route path="/signup" exact component={Signup} /> |
| 86 | + <Route path="/forget" component={Forget} /> |
| 87 | + <Route path="/reset" component={Reset} /> |
| 88 | + <Route path="/report" component={Report} /> |
| 89 | + <Route path="/404" exact component={NotFound} /> |
| 90 | + |
| 91 | + <Redirect to="/404" /> |
| 92 | + </Switch> |
| 93 | + {location.pathname !== "/404" && <Footer fill={"#0D1017"} />} |
| 94 | + </Suspense> |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | +} |
| 103 | + |
| 104 | +export default withRouter(App); |
0 commit comments