diff options
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/App.tsx | 92 |
1 files changed, 60 insertions, 32 deletions
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index bdd3adc..81589f6 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx | |||
| @@ -1,28 +1,30 @@ | |||
| 1 | import React from 'react'; | 1 | import React from "react"; |
| 2 | import { Routes, Route } from "react-router-dom"; | 2 | import { Routes, Route } from "react-router-dom"; |
| 3 | import { Helmet } from "react-helmet"; | 3 | import { Helmet } from "react-helmet"; |
| 4 | 4 | ||
| 5 | import { UserProfile } from '@customTypes/Profile'; | 5 | import { UserProfile } from "@customTypes/Profile"; |
| 6 | import Sidebar from './components/Sidebar'; | 6 | import Sidebar from "./components/Sidebar"; |
| 7 | import "./App.css"; | 7 | import "./App.css"; |
| 8 | 8 | ||
| 9 | import Profile from '@pages/Profile'; | 9 | import Profile from "@pages/Profile"; |
| 10 | import Games from '@pages/Games'; | 10 | import Games from "@pages/Games"; |
| 11 | import Maps from '@pages/Maps'; | 11 | import Maps from "@pages/Maps"; |
| 12 | import User from '@pages/User'; | 12 | import User from "@pages/User"; |
| 13 | import Homepage from '@pages/Homepage'; | 13 | import Homepage from "@pages/Homepage"; |
| 14 | import UploadRunDialog from './components/UploadRunDialog'; | 14 | import UploadRunDialog from "./components/UploadRunDialog"; |
| 15 | import Rules from '@pages/Rules'; | 15 | import Rules from "@pages/Rules"; |
| 16 | import About from '@pages/About'; | 16 | import About from "@pages/About"; |
| 17 | import { Game } from '@customTypes/Game'; | 17 | import { Game } from "@customTypes/Game"; |
| 18 | import { API } from './api/Api'; | 18 | import { API } from "./api/Api"; |
| 19 | import Maplist from '@pages/Maplist'; | 19 | import Maplist from "@pages/Maplist"; |
| 20 | import Rankings from '@pages/Rankings'; | 20 | import Rankings from "@pages/Rankings"; |
| 21 | import { get_user_id_from_token, get_user_mod_from_token } from './utils/Jwt'; | 21 | import { get_user_id_from_token, get_user_mod_from_token } from "./utils/Jwt"; |
| 22 | 22 | ||
| 23 | const App: React.FC = () => { | 23 | const App: React.FC = () => { |
| 24 | const [token, setToken] = React.useState<string | undefined>(undefined); | 24 | const [token, setToken] = React.useState<string | undefined>(undefined); |
| 25 | const [profile, setProfile] = React.useState<UserProfile | undefined>(undefined); | 25 | const [profile, setProfile] = React.useState<UserProfile | undefined>( |
| 26 | undefined | ||
| 27 | ); | ||
| 26 | const [isModerator, setIsModerator] = React.useState<boolean>(false); | 28 | const [isModerator, setIsModerator] = React.useState<boolean>(false); |
| 27 | 29 | ||
| 28 | const [games, setGames] = React.useState<Game[]>([]); | 30 | const [games, setGames] = React.useState<Game[]>([]); |
| @@ -52,15 +54,15 @@ const App: React.FC = () => { | |||
| 52 | setIsModerator(false); | 54 | setIsModerator(false); |
| 53 | } else { | 55 | } else { |
| 54 | setProfile({} as UserProfile); // placeholder before we call actual user profile | 56 | setProfile({} as UserProfile); // placeholder before we call actual user profile |
| 55 | _set_profile(get_user_id_from_token(token)) | 57 | _set_profile(get_user_id_from_token(token)); |
| 56 | const modStatus = get_user_mod_from_token(token) | 58 | const modStatus = get_user_mod_from_token(token); |
| 57 | if (modStatus) { | 59 | if (modStatus) { |
| 58 | setIsModerator(true); | 60 | setIsModerator(true); |
| 59 | } else { | 61 | } else { |
| 60 | setIsModerator(false); | 62 | setIsModerator(false); |
| 61 | } | 63 | } |
| 62 | } | 64 | } |
| 63 | }, [token]); | 65 | }, [token, _set_profile]); |
| 64 | 66 | ||
| 65 | React.useEffect(() => { | 67 | React.useEffect(() => { |
| 66 | _fetch_token(); | 68 | _fetch_token(); |
| @@ -73,23 +75,49 @@ const App: React.FC = () => { | |||
| 73 | <title>LPHUB</title> | 75 | <title>LPHUB</title> |
| 74 | <meta name="description" content="Least Portals Hub" /> | 76 | <meta name="description" content="Least Portals Hub" /> |
| 75 | </Helmet> | 77 | </Helmet> |
| 76 | <UploadRunDialog token={token} open={uploadRunDialog} onClose={(updateProfile) => { | 78 | <UploadRunDialog |
| 77 | setUploadRunDialog(false); | 79 | token={token} |
| 78 | if (updateProfile) { | 80 | open={uploadRunDialog} |
| 79 | _set_profile(get_user_id_from_token(token)); | 81 | onClose={(updateProfile) => { |
| 80 | } | 82 | setUploadRunDialog(false); |
| 81 | }} games={games} /> | 83 | if (updateProfile) { |
| 82 | <Sidebar setToken={setToken} profile={profile} setProfile={setProfile} onUploadRun={() => setUploadRunDialog(true)} /> | 84 | _set_profile(get_user_id_from_token(token)); |
| 85 | } | ||
| 86 | }} | ||
| 87 | games={games} | ||
| 88 | /> | ||
| 89 | <Sidebar | ||
| 90 | setToken={setToken} | ||
| 91 | profile={profile} | ||
| 92 | setProfile={setProfile} | ||
| 93 | onUploadRun={() => setUploadRunDialog(true)} | ||
| 94 | /> | ||
| 83 | <Routes> | 95 | <Routes> |
| 84 | <Route path="/" element={<Homepage />} /> | 96 | <Route path="/" element={<Homepage />} /> |
| 85 | <Route path="/profile" element={<Profile profile={profile} token={token} gameData={games} onDeleteRecord={() => _set_profile(get_user_id_from_token(token))} />} /> | 97 | <Route |
| 86 | <Route path="/users/*" element={<User profile={profile} token={token} gameData={games} />} /> | 98 | path="/profile" |
| 99 | element={ | ||
| 100 | <Profile | ||
| 101 | profile={profile} | ||
| 102 | token={token} | ||
| 103 | gameData={games} | ||
| 104 | onDeleteRecord={() => _set_profile(get_user_id_from_token(token))} | ||
| 105 | /> | ||
| 106 | } | ||
| 107 | /> | ||
| 108 | <Route | ||
| 109 | path="/users/*" | ||
| 110 | element={<User profile={profile} token={token} gameData={games} />} | ||
| 111 | /> | ||
| 87 | <Route path="/games" element={<Games games={games} />} /> | 112 | <Route path="/games" element={<Games games={games} />} /> |
| 88 | <Route path='/games/:id' element={<Maplist />}></Route> | 113 | <Route path="/games/:id" element={<Maplist />}></Route> |
| 89 | <Route path="/maps/*" element={<Maps token={token} isModerator={isModerator} />} /> | 114 | <Route |
| 115 | path="/maps/*" | ||
| 116 | element={<Maps token={token} isModerator={isModerator} />} | ||
| 117 | /> | ||
| 90 | <Route path="/rules" element={<Rules />} /> | 118 | <Route path="/rules" element={<Rules />} /> |
| 91 | <Route path="/about" element={<About />} /> | 119 | <Route path="/about" element={<About />} /> |
| 92 | <Route path='/rankings' element={<Rankings />}></Route> | 120 | <Route path="/rankings" element={<Rankings />}></Route> |
| 93 | <Route path="*" element={"404"} /> | 121 | <Route path="*" element={"404"} /> |
| 94 | </Routes> | 122 | </Routes> |
| 95 | </> | 123 | </> |