diff options
| author | Wolfboy248 <georgejvindkarlsen@gmail.com> | 2024-10-28 11:43:38 +0100 |
|---|---|---|
| committer | Wolfboy248 <georgejvindkarlsen@gmail.com> | 2024-10-28 11:43:38 +0100 |
| commit | 6fdc20a4db98531545badedf983a81a05f0ea450 (patch) | |
| tree | 69d314fd8fad33cc12c676617b5bc1c6ff066cce /frontend/src/App.tsx | |
| parent | refactor: uploadrundialog (diff) | |
| parent | backend: fix user completion count (diff) | |
| download | lphub-6fdc20a4db98531545badedf983a81a05f0ea450.tar.gz lphub-6fdc20a4db98531545badedf983a81a05f0ea450.tar.bz2 lphub-6fdc20a4db98531545badedf983a81a05f0ea450.zip | |
Merge branch 'typescript' of https://github.com/pektezol/LeastPortalsHub into typescript
Diffstat (limited to 'frontend/src/App.tsx')
| -rw-r--r-- | frontend/src/App.tsx | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d1d501d..c6952b1 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | import React from 'react'; | 1 | import React from 'react'; |
| 2 | import { Routes, Route, useLocation } from "react-router-dom"; | 2 | import { Routes, Route } from "react-router-dom"; |
| 3 | 3 | ||
| 4 | import { UserProfile } from './types/Profile'; | 4 | import { UserProfile } from './types/Profile'; |
| 5 | import Sidebar from './components/Sidebar'; | 5 | import Sidebar from './components/Sidebar'; |
| @@ -18,22 +18,15 @@ import { API } from './api/Api'; | |||
| 18 | import Maplist from './pages/Maplist'; | 18 | import Maplist from './pages/Maplist'; |
| 19 | import Rankings from './pages/Rankings'; | 19 | import Rankings from './pages/Rankings'; |
| 20 | import { get_user_id_from_token, get_user_mod_from_token } from './utils/Jwt'; | 20 | import { get_user_id_from_token, get_user_mod_from_token } from './utils/Jwt'; |
| 21 | import { MapDeleteEndpoint } from './types/Map'; | ||
| 22 | 21 | ||
| 23 | const App: React.FC = () => { | 22 | const App: React.FC = () => { |
| 24 | const [token, setToken] = React.useState<string | undefined>(undefined); | 23 | const [token, setToken] = React.useState<string | undefined>(undefined); |
| 25 | const [profile, setProfile] = React.useState<UserProfile | undefined>(undefined); | 24 | const [profile, setProfile] = React.useState<UserProfile | undefined>(undefined); |
| 26 | const [isModerator, setIsModerator] = React.useState<boolean>(false); | 25 | const [isModerator, setIsModerator] = React.useState<boolean>(false); |
| 27 | 26 | ||
| 28 | const [msgIsOpen, setMsgIsOpen] = React.useState<boolean>(false); | ||
| 29 | |||
| 30 | const [games, setGames] = React.useState<Game[]>([]); | 27 | const [games, setGames] = React.useState<Game[]>([]); |
| 31 | 28 | ||
| 32 | const [uploadRunDialog, setUploadRunDialog] = React.useState<boolean>(false); | 29 | const [uploadRunDialog, setUploadRunDialog] = React.useState<boolean>(false); |
| 33 | const [uploadRunDialogMapID, setUploadRunDialogMapID] = React.useState<number | undefined>(undefined); | ||
| 34 | |||
| 35 | const [confirmDialogOpen, setConfirmDialogOpen] = React.useState<boolean>(false); | ||
| 36 | const [currDeleteMapInfo, setCurrDeleteMapInfo] = React.useState<MapDeleteEndpoint>(); | ||
| 37 | 30 | ||
| 38 | const _fetch_token = async () => { | 31 | const _fetch_token = async () => { |
| 39 | const token = await API.get_token(); | 32 | const token = await API.get_token(); |
| @@ -45,10 +38,9 @@ const App: React.FC = () => { | |||
| 45 | setGames(games); | 38 | setGames(games); |
| 46 | }; | 39 | }; |
| 47 | 40 | ||
| 48 | const _set_profile = async (user_id: string | undefined) => { | 41 | const _set_profile = async (user_id?: string) => { |
| 49 | if (user_id) { | 42 | if (user_id && token) { |
| 50 | setProfile({} as UserProfile); // placeholder before we call actual user profile | 43 | const user = await API.get_profile(token); |
| 51 | const user = await API.get_profile(token!); | ||
| 52 | setProfile(user); | 44 | setProfile(user); |
| 53 | } | 45 | } |
| 54 | }; | 46 | }; |
| @@ -58,6 +50,7 @@ const App: React.FC = () => { | |||
| 58 | setProfile(undefined); | 50 | setProfile(undefined); |
| 59 | setIsModerator(false); | 51 | setIsModerator(false); |
| 60 | } else { | 52 | } else { |
| 53 | setProfile({} as UserProfile); // placeholder before we call actual user profile | ||
| 61 | _set_profile(get_user_id_from_token(token)) | 54 | _set_profile(get_user_id_from_token(token)) |
| 62 | const modStatus = get_user_mod_from_token(token) | 55 | const modStatus = get_user_mod_from_token(token) |
| 63 | if (modStatus) { | 56 | if (modStatus) { |
| @@ -81,15 +74,20 @@ const App: React.FC = () => { | |||
| 81 | 74 | ||
| 82 | return ( | 75 | return ( |
| 83 | <> | 76 | <> |
| 84 | <UploadRunDialog token={token} open={uploadRunDialog} onClose={() => setUploadRunDialog(false)} games={games} /> | 77 | <UploadRunDialog token={token} open={uploadRunDialog} onClose={(updateProfile) => { |
| 78 | setUploadRunDialog(false); | ||
| 79 | if (updateProfile) { | ||
| 80 | _set_profile(get_user_id_from_token(token)); | ||
| 81 | } | ||
| 82 | }} games={games} /> | ||
| 85 | <Sidebar setToken={setToken} profile={profile} setProfile={setProfile} onUploadRun={() => setUploadRunDialog(true)} /> | 83 | <Sidebar setToken={setToken} profile={profile} setProfile={setProfile} onUploadRun={() => setUploadRunDialog(true)} /> |
| 86 | <Routes> | 84 | <Routes> |
| 87 | <Route path="/" element={<Homepage />} /> | 85 | <Route path="/" element={<Homepage />} /> |
| 88 | <Route path="/profile" element={<Profile profile={profile} token={token} gameData={games} onDeleteRecord={() => setConfirmDialogOpen(true)} />} /> | 86 | <Route path="/profile" element={<Profile profile={profile} token={token} gameData={games} onDeleteRecord={() => _set_profile(get_user_id_from_token(token))} />} /> |
| 89 | <Route path="/users/*" element={<User profile={profile} token={token} gameData={games} />} /> | 87 | <Route path="/users/*" element={<User profile={profile} token={token} gameData={games} />} /> |
| 90 | <Route path="/games" element={<Games games={games} />} /> | 88 | <Route path="/games" element={<Games games={games} />} /> |
| 91 | <Route path='/games/:id' element={<Maplist />}></Route> | 89 | <Route path='/games/:id' element={<Maplist />}></Route> |
| 92 | <Route path="/maps/*" element={<Maps token={token} isModerator={isModerator} />}/> | 90 | <Route path="/maps/*" element={<Maps token={token} isModerator={isModerator} />} /> |
| 93 | <Route path="/rules" element={<Rules />} /> | 91 | <Route path="/rules" element={<Rules />} /> |
| 94 | <Route path="/about" element={<About />} /> | 92 | <Route path="/about" element={<About />} /> |
| 95 | <Route path='/rankings' element={<Rankings />}></Route> | 93 | <Route path='/rankings' element={<Rankings />}></Route> |