{"size": 1294, "ext": "js", "max_stars_repo_path": "src/App.js", "max_stars_repo_name": "ArkadiiAP/usof-frontend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/App.js", "max_issues_repo_name": "ArkadiiAP/usof-frontend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/App.js", "max_forks_repo_name": "ArkadiiAP/usof-frontend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.3725490196, "max_line_length": 69, "alphanum_fraction": 0.6221020093}
import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import Header from "./components/header/Header";
import {BrowserRouter as Router} from "react-router-dom";
import Body from "./components/body/Body";
import React, {useEffect} from "react";
import {useDispatch, useSelector} from "react-redux";
import axios from "axios";
import {get_token, login, logout} from "./store/reducers";
import {getMyAccount} from "./services";

function App() {
  const dispatch = useDispatch()
  const token = useSelector(state => state.tokenReducer.token)
  const auth = useSelector(state => state.authReducer)

  useEffect(() => {
    const logInOnStartUp = localStorage.getItem('logInOnStartUp')
    if(logInOnStartUp){
      const getToken = async () => {
        const res = await axios.post('/api/auth/refresh_token', null)
        dispatch(get_token(res.data.access_token))
      }
      getToken()
    }
  },[auth.isLogged, dispatch]) //

  useEffect(() => {
    if(token){
      const getUser = () => {
        dispatch(login())
        dispatch(getMyAccount(token))
      }
      getUser()
    }
  },[token, dispatch])

  return (
      <Router>
          <div className="App">
              <Header />
              <Body />
          </div>
      </Router>

  );
}


export default App;
