text: import './App.css';
  import React, { useState, useEffect } from "react";
  import useLocalStorage from "./hooks/useLocalStorage";
  import Navigation from "./routes/Navigation";
  import Routes from "./routes/Routes";
  import JoblyApi from "./api/api";
  import { BrowserRouter } from "react-router-dom";
  import jwt from "jsonwebtoken";
  import UserContext from "./auth/UserContext";
  
  function App() {
      const [loaded, setLoaded] = useState(false);
      const [currentUser, setCurrentUser] = useState(null);
      const [token, setToken] = useLocalStorage(TOKEN);
      const [applicationIds, setApplicationIds] = useState(new Set([]));
  
      useEffect(function initialLoad() {
          async function getCurrentUser() {
              if (token) {
                  try {
                  let { username } = jwt.decode(token);
                  JoblyApi.token = token;
                  let currentUser = await JoblyApi.getCurrentUser(username);
                  setCurrentUser(currentUser);
                  setApplicationIds(new Set(currentUser.applications));
              } catch (err) {
                  console.error("Problem Loading!!", err);
                  setCurrentUser(null);
              }
          }
              setLoaded(true);
          }
          setLoaded(false);
          getCurrentUser();
      }, [token]);
  
  
  
      async function signup(signupData) {
          try {
              let token = await JoblyApi.signup(signupData);
              setToken(token);
              return { success: true };
          } catch (errors) {
              console.error("signup failed", errors);
              return { success: false, errors };
          }
      }
  
      async function login(loginData) {
          try {
              let token = await JoblyApi.login(loginData);
              setToken(token);
              return { success: true };
          } catch (errors) {
              console.error("login failed", errors);
              return { success: false, errors };
          }
        }
  
      function logout() {
          setCurrentUser(null);
          setToken(null);
      }
  
      function hasApplied(id) {
          return applicationIds.has(id);
      }
  
      function applyToJob(id) {
          if (hasApplied(id)) return;
          JoblyApi.applyToJob(currentUser.username, id);
          setApplicationIds(new Set([...applicationIds, id]));
      }
  
      if (!loaded) return ":)";
  
      return (
          <div className="App">
              <BrowserRouter>
                  <UserContext.Provider
                      value={{ currentUser, setCurrentUser, hasApplied, applyToJob }}>
                      <div>
                          <Navigation logout={logout} />
                          <Routes login={login} signup={signup} />
                      </div>
                  </UserContext.Provider>
              </BrowserRouter>
          </div>
      );
  }
  
  export const TOKEN = "my token";
  export default App;
  