From b5e7c51e5f54bcb00e3160603e8c0337d5bb480f Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Mon, 14 Dec 2020 00:02:38 +0100 Subject: [PATCH] Fix refresh --- .eslintcache | 2 +- src/App.js | 68 +++++++++++++++++++++++++++++++----- src/Components/Navigation.js | 45 ------------------------ 3 files changed, 60 insertions(+), 55 deletions(-) delete mode 100644 src/Components/Navigation.js diff --git a/.eslintcache b/.eslintcache index b474d01f..e22bf8dc 100644 --- a/.eslintcache +++ b/.eslintcache @@ -1 +1 @@ -[{"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\index.js":"1","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\History.js":"2","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\App.js":"3","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Dash.js":"4","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Constants\\constants.js":"5","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Loading.js":"6","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Navigation.js":"7","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\System.js":"8","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Memberlist.js":"9","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\MemberCard.js":"10","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Functions\\discord-parser.js":"11","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Footer.js":"12","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Profile.js":"13"},{"size":329,"mtime":1607895960007,"results":"14","hashOfConfig":"15"},{"size":87,"mtime":1607504507181,"results":"16","hashOfConfig":"15"},{"size":5394,"mtime":1607898785732,"results":"17","hashOfConfig":"15"},{"size":243,"mtime":1607696817140,"results":"18","hashOfConfig":"15"},{"size":73,"mtime":1607504507180,"results":"19","hashOfConfig":"15"},{"size":231,"mtime":1607504507174,"results":"20","hashOfConfig":"15"},{"size":1775,"mtime":1607899033295,"results":"21","hashOfConfig":"15"},{"size":10249,"mtime":1607892068230,"results":"22","hashOfConfig":"15"},{"size":14056,"mtime":1607899022832,"results":"23","hashOfConfig":"15"},{"size":19256,"mtime":1607893177574,"results":"24","hashOfConfig":"15"},{"size":10382,"mtime":1607549930730,"results":"25","hashOfConfig":"15"},{"size":741,"mtime":1607797507192,"results":"26","hashOfConfig":"15"},{"size":436,"mtime":1607896148590,"results":"27","hashOfConfig":"15"},{"filePath":"28","messages":"29","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1uc84gl",{"filePath":"30","messages":"31","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"33","messages":"34","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"35","messages":"36","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"37","messages":"38","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"39","messages":"40","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"41","messages":"42","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"43","messages":"44","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"45","messages":"46","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"47","messages":"48","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"49","messages":"50","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"51","messages":"52","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"32"},{"filePath":"53","messages":"54","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\index.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\History.js",[],["55","56"],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\App.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Dash.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Constants\\constants.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Loading.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Navigation.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\System.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Memberlist.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\MemberCard.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Functions\\discord-parser.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Footer.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Profile.js",[],{"ruleId":"57","replacedBy":"58"},{"ruleId":"59","replacedBy":"60"},"no-native-reassign",["61"],"no-negated-in-lhs",["62"],"no-global-assign","no-unsafe-negation"] \ No newline at end of file +[{"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\index.js":"1","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\History.js":"2","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\App.js":"3","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Dash.js":"4","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Constants\\constants.js":"5","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Loading.js":"6","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\System.js":"7","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Memberlist.js":"8","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\MemberCard.js":"9","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Functions\\discord-parser.js":"10","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Footer.js":"11","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Profile.js":"12","C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Navigation.js":"13"},{"size":329,"mtime":1607895960007,"results":"14","hashOfConfig":"15"},{"size":87,"mtime":1607504507181,"results":"16","hashOfConfig":"15"},{"size":7704,"mtime":1607900527875,"results":"17","hashOfConfig":"15"},{"size":243,"mtime":1607696817140,"results":"18","hashOfConfig":"15"},{"size":73,"mtime":1607504507180,"results":"19","hashOfConfig":"15"},{"size":231,"mtime":1607504507174,"results":"20","hashOfConfig":"15"},{"size":10249,"mtime":1607892068230,"results":"21","hashOfConfig":"15"},{"size":14056,"mtime":1607899022832,"results":"22","hashOfConfig":"15"},{"size":19256,"mtime":1607893177574,"results":"23","hashOfConfig":"15"},{"size":10382,"mtime":1607549930730,"results":"24","hashOfConfig":"15"},{"size":741,"mtime":1607797507192,"results":"25","hashOfConfig":"15"},{"size":436,"mtime":1607896148590,"results":"26","hashOfConfig":"15"},{"size":1775,"mtime":1607899033295,"results":"27","hashOfConfig":"15"},{"filePath":"28","messages":"29","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1uc84gl",{"filePath":"30","messages":"31","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\index.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\History.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\App.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Dash.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Constants\\constants.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Loading.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\System.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Memberlist.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\MemberCard.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Functions\\discord-parser.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Footer.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Profile.js",[],"C:\\Users\\Fleur\\Desktop\\website projects etc\\pk-web\\src\\Components\\Navigation.js",[]] \ No newline at end of file diff --git a/src/App.js b/src/App.js index 93f70986..9d16c8ce 100644 --- a/src/App.js +++ b/src/App.js @@ -4,17 +4,16 @@ 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 { FaLock } from "react-icons/fa"; -import { FaCog } from "react-icons/fa"; - +import "react-toggle/style.css" +import { FaLock, 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 Navigation from "./Components/Navigation.js"; import Footer from './Components/Footer.js' import Profile from './Components/Profile.js' @@ -27,12 +26,13 @@ export default function App() { 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')) { - logIn(); + checkLogIn(); } }, []) @@ -41,6 +41,13 @@ export default function App() { logIn(); }; + function logOut() { + setIsSubmit(false); + localStorage.removeItem("token"); + localStorage.removeItem("user"); + history.push('/pk-webs'); + forceUpdate(); +} function logIn() { setIsInvalid(false); @@ -66,11 +73,52 @@ export default function App() { }) }; + 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 (
- + + + pk-webs + + + { localStorage.getItem('token') ? logOut()}>Log out : "" } + history.push('/pk-webs/dash')} >Dash + history.push('/pk-webs/settings')} >Settings + history.push('/pk-webs/profile')}>Public profile + + + + + {darkMode.value ? : } + + @@ -84,9 +132,11 @@ export default function App() { Login - - { isSubmit && !localStorage.getItem('user') ? Something went wrong, please try again. : ""} + { isSubmit && !localStorage.getItem('user') ? Something went wrong, please try again. : ""} { isInvalid ? Invalid token. : "" } + { localStorage.getItem('user') && localStorage.getItem('token') ? <>

You are logged in already, click here to continue to the dash.

+ history.push('/pk-webs/dash')}>Continue to dash : + Enter your token here. You can get your token by using "pk;token". @@ -100,7 +150,7 @@ export default function App() { Submit - +
}
} diff --git a/src/Components/Navigation.js b/src/Components/Navigation.js deleted file mode 100644 index a637ced4..00000000 --- a/src/Components/Navigation.js +++ /dev/null @@ -1,45 +0,0 @@ -import { useState, useCallback } from 'react'; -import * as BS from 'react-bootstrap' -import useDarkMode from 'use-dark-mode'; -import Toggle from 'react-toggle' -import { FaSun, FaMoon } from "react-icons/fa"; - -import "react-toggle/style.css" -import history from "../History.js"; - -export default function Navigation() { - - const [, updateState] = useState(); - const forceUpdate = useCallback(() => updateState({}), []); - - const darkMode = useDarkMode(false); - - function logOut() { - localStorage.removeItem("token"); - localStorage.removeItem("user"); - history.push('/pk-webs'); - forceUpdate(); - } - - return ( - - - pk-webs - - - { localStorage.getItem('token') ? logOut()}>Log out : "" } - history.push('/pk-webs/dash')} >Dash - history.push('/pk-webs/settings')} >Settings - history.push('/pk-webs/profile')}>Public profile - - - - - {darkMode.value ? : } - - - ) -} \ No newline at end of file