All files / src/components App.tsx

0% Statements 0/17
0% Branches 0/8
0% Functions 0/2
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87                                                                                                                                                                             
import React, { ReactElement } from "react";
import "./App.css";
import Header from "./basicElements/Header";
import Footer from "./basicElements/Footer";
import { BrowserRouter } from "react-router-dom";
import Router from "./Router/Router";
import PermanentAssets from "./basicElements/PermanentAssets";
 
import { connect, ConnectedProps } from "react-redux";
import {
  addAccessToken,
  addRefreshToken,
  checkedCookies
} from "../background/redux/actions/tokens";
import { SystemState } from "../background/redux/actions/sytemState";
 
import Login from "./basicElements/Login";
import { checkForCookie } from "../background/api/auth";
import { TopBanner } from "./basicElements/TopBanner";
import { FFLoading } from "./basicElements/Loading";
import { CookieStatus } from "../background/redux/actions/tokenTypes";
import {BottomBanner} from "./basicElements/BottomBanner";
 
// this takes the redux store and maps everything that is needed to the function props
const mapState = (state: SystemState) => ({
  tokens: {
    refreshToken: state.tokens.refreshToken,
    accessToken: state.tokens.accessToken,
    checkedCookies: state.tokens.checkedCookies
  },
  user: state.user
});
 
// this takes the redux actions and maps them to the props
const mapDispatch = {
  addRefreshToken,
  addAccessToken,
  checkedCookies
};
 
const connector = connect(mapState, mapDispatch);
 
type PropsFromRedux = ConnectedProps<typeof connector>;
 
// this defines the component props and also adds the redux imported props
type Props = PropsFromRedux;
 
function App(props: Props): ReactElement {
  console.log("[App] props.tokens: ");
  console.log(props.tokens.refreshToken);
  console.log(props.tokens);
  console.log(props.user);
  console.log("[App]---------------");
 
  if (props.tokens.checkedCookies === CookieStatus.FINISHED) {
    if (props.tokens.refreshToken && props.tokens.accessToken?.token) {
      return (
        <div className="App h-100 d-flex flex-column">
          <BrowserRouter>
            <TopBanner />
            <Header />
            <div>
              <main role="main" className={"flex-shrink-0 flex-grow-1"}>
                <Router />
              </main>
            </div>
            <Footer />
            <BottomBanner/>
            <PermanentAssets />
          </BrowserRouter>
        </div>
      );
    } else {
      console.log("[APP] showing login");
      return <Login />;
    }
  } else {
    if (props.tokens.checkedCookies === CookieStatus.NOT_STARTED) {
      checkForCookie();
    }
 
    return <FFLoading />;
  }
}
 
export default connector(App);