2021-06-26 19:36:46 +02:00
|
|
|
import React, { useState, useCallback} from 'react';
|
2020-12-09 09:15:55 +01:00
|
|
|
import { Router, Switch, Route, Redirect } from 'react-router-dom';
|
|
|
|
|
import * as BS from 'react-bootstrap'
|
2020-12-13 23:38:10 +01:00
|
|
|
import Toggle from 'react-toggle'
|
2020-12-14 00:02:38 +01:00
|
|
|
import useDarkMode from 'use-dark-mode';
|
2020-12-09 09:15:55 +01:00
|
|
|
|
2020-12-09 17:45:11 +01:00
|
|
|
import './App.scss';
|
2020-12-09 09:15:55 +01:00
|
|
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
2020-12-14 00:02:38 +01:00
|
|
|
import "react-toggle/style.css"
|
2021-06-26 20:12:56 +02:00
|
|
|
import { FaSun, FaMoon } from "react-icons/fa";
|
2020-12-09 09:15:55 +01:00
|
|
|
|
2021-06-26 19:51:14 +02:00
|
|
|
import Dash from './Pages/Dash.js'
|
2020-12-09 09:15:55 +01:00
|
|
|
import history from "./History.js";
|
2020-12-12 19:19:22 +01:00
|
|
|
import Footer from './Components/Footer.js'
|
2021-06-26 19:51:14 +02:00
|
|
|
import Public from './Pages/Public.js'
|
2021-06-26 19:36:46 +02:00
|
|
|
import Home from './Pages/Home.js'
|
2021-06-26 20:12:56 +02:00
|
|
|
import Settings from './Pages/Settings.js'
|
2020-12-09 09:15:55 +01:00
|
|
|
|
|
|
|
|
export default function App() {
|
2021-06-26 19:36:46 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [isSubmit, setIsSubmit] = useState(false);
|
2020-12-09 09:15:55 +01:00
|
|
|
const [isInvalid, setIsInvalid] = useState(false);
|
2021-06-26 19:36:46 +02:00
|
|
|
|
2020-12-13 23:38:10 +01:00
|
|
|
const [, updateState] = useState();
|
|
|
|
|
const forceUpdate = useCallback(() => updateState({}), []);
|
2020-12-14 00:02:38 +01:00
|
|
|
const darkMode = useDarkMode(false);
|
2020-12-09 09:15:55 +01:00
|
|
|
|
2020-12-14 00:02:38 +01:00
|
|
|
function logOut() {
|
|
|
|
|
setIsSubmit(false);
|
|
|
|
|
localStorage.removeItem("token");
|
|
|
|
|
localStorage.removeItem("user");
|
2021-06-26 19:36:46 +02:00
|
|
|
history.push("/pk-webs");
|
2020-12-14 00:02:38 +01:00
|
|
|
forceUpdate();
|
2021-06-26 19:36:46 +02:00
|
|
|
}
|
2020-12-09 08:32:35 +01:00
|
|
|
|
|
|
|
|
return (
|
2021-01-06 13:10:40 +01:00
|
|
|
<div className={ `contents ${localStorage.getItem('opendyslexic') ? "opendyslexic" : ""}`}>
|
2020-12-09 23:56:35 +01:00
|
|
|
<Router history={history} basename="/pk-webs">
|
2020-12-14 00:02:38 +01:00
|
|
|
<BS.Navbar className="mb-5 align-items-center">
|
|
|
|
|
<BS.Navbar.Brand href="/pk-webs">
|
|
|
|
|
pk-webs
|
|
|
|
|
</BS.Navbar.Brand>
|
|
|
|
|
<BS.NavDropdown id="menu" className="mr-auto" title="Menu">
|
2021-02-06 17:02:26 +01:00
|
|
|
<BS.NavDropdown.Item onClick={() => history.push('/pk-webs/dash')} >Dash</BS.NavDropdown.Item>
|
2020-12-14 00:02:38 +01:00
|
|
|
<BS.NavDropdown.Item onClick={() => history.push('/pk-webs/settings')} >Settings</BS.NavDropdown.Item>
|
|
|
|
|
<BS.NavDropdown.Item onClick={() => history.push('/pk-webs/profile')}>Public profile</BS.NavDropdown.Item>
|
2020-12-14 22:25:35 +01:00
|
|
|
{ localStorage.getItem('token') ? <><hr className="my-1"/><BS.NavDropdown.Item onClick={() => logOut()}>Log out</BS.NavDropdown.Item></> : "" }
|
2020-12-14 00:02:38 +01:00
|
|
|
|
|
|
|
|
</BS.NavDropdown>
|
2020-12-14 22:25:35 +01:00
|
|
|
<BS.Nav className="mr-2 d-flex align-items-center row">
|
2020-12-14 00:02:38 +01:00
|
|
|
<Toggle
|
|
|
|
|
defaultChecked={true}
|
|
|
|
|
icons={false}
|
|
|
|
|
onChange={darkMode.toggle} />
|
|
|
|
|
{darkMode.value ? <FaMoon className="m-1"/> : <FaSun className="m-1"/>}
|
|
|
|
|
</BS.Nav>
|
|
|
|
|
</BS.Navbar>
|
2021-01-06 13:10:40 +01:00
|
|
|
<div className="content">
|
2020-12-09 09:15:55 +01:00
|
|
|
<BS.Container>
|
|
|
|
|
<Switch>
|
2021-01-06 00:05:34 +01:00
|
|
|
<Route path="/pk-webs/dash">
|
2020-12-11 16:35:25 +01:00
|
|
|
{ !localStorage.getItem('token') || isInvalid ? <Redirect to="/pk-webs"/> : <Dash />
|
2020-12-09 09:15:55 +01:00
|
|
|
}
|
|
|
|
|
</Route>
|
2020-12-09 09:32:20 +01:00
|
|
|
<Route exact path="/pk-webs">
|
2021-06-26 19:36:46 +02:00
|
|
|
<Home isLoading={isLoading} setIsLoading={setIsLoading} isSubmit={isSubmit} setIsSubmit={setIsSubmit} isInvalid={isInvalid} setIsInvalid={setIsInvalid}/>
|
2020-12-09 09:15:55 +01:00
|
|
|
</Route>
|
2020-12-14 22:25:35 +01:00
|
|
|
<Route path="/pk-webs/profile">
|
|
|
|
|
<Public />
|
2020-12-13 23:38:10 +01:00
|
|
|
</Route>
|
2020-12-14 22:25:35 +01:00
|
|
|
<Route path="/pk-webs/settings">
|
2021-06-26 20:12:56 +02:00
|
|
|
<Settings forceUpdate={forceUpdate}/>
|
2020-12-13 23:38:10 +01:00
|
|
|
</Route>
|
2020-12-09 09:15:55 +01:00
|
|
|
</Switch>
|
|
|
|
|
</BS.Container>
|
2021-01-06 13:10:40 +01:00
|
|
|
</div>
|
2020-12-12 19:19:22 +01:00
|
|
|
<Footer />
|
2020-12-09 09:15:55 +01:00
|
|
|
</Router>
|
2020-12-13 23:38:10 +01:00
|
|
|
</div>
|
2020-12-09 08:32:35 +01:00
|
|
|
);
|
|
|
|
|
}
|