{"size": 2555, "ext": "js", "max_stars_repo_path": "src/app/App.js", "max_stars_repo_name": "hagomanda/hagomanda", "max_stars_repo_stars_event_min_datetime": "2022-02-10T07:16:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T07:16:01.000Z", "max_issues_repo_path": "src/app/App.js", "max_issues_repo_name": "hagomanda/hagomanda", "max_issues_repo_issues_event_min_datetime": "2022-02-09T01:01:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T00:15:01.000Z", "max_forks_repo_path": "src/app/App.js", "max_forks_repo_name": "hagomanda/frontend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 26, "max_forks_count": null, "avg_line_length": 30.4166666667, "max_line_length": 80, "alphanum_fraction": 0.6152641879}
import React, { useEffect } from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import axios from "axios";

import { refresh } from "../reducers/userSlice";
import IndexPage from "../components/IndexPage";
import GlobalNavBar from "../components/Header/GlobalNavBar";
import Navbar from "../components/Header/Navbar";
import LoginPage from "../components/LoginPage";
import Main from "../components/Main/Main";
import CalendarPage from "../components/Calendar/CalendarPage";
import MandalPage from "../components/Mandal/MandalPage";
import MyPage from "../components/MyPage";
import ErrorPage from "../components/shared/ErrorPage";

axios.defaults.baseURL = process.env.REACT_APP_SERVER_URL;
axios.defaults.withCredentials = true;
const JWT_EXPIRY_TIME = 1000 * 60 * 59;

let refreshLoginTime = null;

function App() {
  const dispatch = useDispatch();
  const loginState = useSelector(state => state.user.loginSucceed);
  const logoutState = useSelector(state => state.user.logoutSucceed);
  const refreshLoginState = useSelector(state => state.user.refreshLogin);
  function setRefreshTimer() {
    refreshLoginTime = setTimeout(() => dispatch(refresh()), JWT_EXPIRY_TIME);
  }
  function clearRefreshTimer() {
    clearTimeout(refreshLoginTime);
  }

  useEffect(() => {
    dispatch(refresh());
  }, []);

  useEffect(() => {
    if (refreshLoginState) {
      setRefreshTimer();
    }
  }, [refreshLoginState]);

  useEffect(() => {
    if (logoutState) {
      clearRefreshTimer();
    }
  }, [logoutState]);

  return (
    <>
      <BrowserRouter>
        <GlobalNavBar />
        {loginState && <Navbar />}
        <Routes>
          <Route path="/" element={<IndexPage />} />
          <Route path="/login" element={<LoginPage />} />
          <Route path="/home" element={loginState ? <Main /> : <LoginPage />} />
          <Route
            path="/mypage"
            element={loginState ? <MyPage /> : <LoginPage />}
          />
          <Route
            path="/mainGoal/:id"
            element={loginState ? <MandalPage /> : <LoginPage />}
          />
          <Route path="/main" element={loginState ? <Main /> : <LoginPage />} />
          <Route
            path="/calendar"
            element={loginState ? <CalendarPage /> : <LoginPage />}
          />
          <Route
            path="/*"
            element={<ErrorPage message="존재하지 않는 페이지입니다." />}
          />
        </Routes>
      </BrowserRouter>
    </>
  );
}

export default App;
