diff --git a/src/App.js b/src/App.js index 5770c846..38574def 100644 --- a/src/App.js +++ b/src/App.js @@ -1,101 +1,36 @@ -import React, {useEffect, useState, useCallback} from 'react'; +import React, { useState, useCallback} from 'react'; import { Router, Switch, Route, Redirect } from 'react-router-dom'; import * as BS from 'react-bootstrap' -import { useForm } from "react-hook-form"; -import * as fetch from 'node-fetch'; import Toggle from 'react-toggle' import useDarkMode from 'use-dark-mode'; import './App.scss'; import 'bootstrap/dist/css/bootstrap.min.css'; import "react-toggle/style.css" -import { FaLock, FaCog, FaSun, FaMoon } from "react-icons/fa"; +import { FaCog, FaSun, FaMoon } from "react-icons/fa"; import Dash from './Components/Dash.js' import history from "./History.js"; -import Loading from "./Components/Loading.js"; import Footer from './Components/Footer.js' import Public from './Components/Public.js' - -import API_URL from "./Constants/constants.js"; +import Home from './Pages/Home.js' export default function App() { - - const [isLoading, setIsLoading ] = useState(false); - const [isSubmit, setIsSubmit ] = useState(false); + const [isLoading, setIsLoading] = useState(false); + const [isSubmit, setIsSubmit] = useState(false); const [isInvalid, setIsInvalid] = useState(false); + const [, updateState] = useState(); const forceUpdate = useCallback(() => updateState({}), []); const darkMode = useDarkMode(false); - const { register, handleSubmit } = useForm(); - - useEffect(() => { - if (localStorage.getItem('token')) { - checkLogIn(); - } - }, []) - - const onSubmit = data => { - localStorage.setItem('token', data.pkToken); - logIn(); - }; - function logOut() { setIsSubmit(false); localStorage.removeItem("token"); localStorage.removeItem("user"); - history.push('/pk-webs'); + history.push("/pk-webs"); forceUpdate(); -} - - function logIn() { - setIsInvalid(false); - setIsLoading(true); - - fetch(`${API_URL}s/`,{ - method: 'GET', - headers: { - 'Authorization': JSON.stringify(localStorage.getItem("token")).slice(1, -1) - }}).then ( res => res.json() - ).then (data => { - localStorage.setItem('user', JSON.stringify(data)); - setIsSubmit(true); - setIsLoading(false); - history.push("/pk-webs/dash"); - }) - .catch (error => { - console.log(error); - setIsInvalid(true); - localStorage.removeItem('token'); - localStorage.removeItem('user'); - setIsLoading(false); - }) - }; - - function checkLogIn() { - setIsInvalid(false); - setIsLoading(true); - - fetch(`${API_URL}s/`,{ - method: 'GET', - headers: { - 'Authorization': JSON.stringify(localStorage.getItem("token")).slice(1, -1) - }}).then ( res => res.json() - ).then (data => { - localStorage.setItem('user', JSON.stringify(data)); - setIsSubmit(true); - setIsLoading(false); - }) - .catch (error => { - console.log(error); - setIsInvalid(true); - localStorage.removeItem('token'); - localStorage.removeItem('user'); - setIsLoading(false); - }) - }; - + } return (
You are logged in already, click here to continue to the dash.
-+ You are logged in already, click here to continue to the dash. +
+