From 89560a61bc6e41d86acaea596762eda2da38fe50 Mon Sep 17 00:00:00 2001
From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>
Date: Mon, 9 Sep 2024 19:29:42 +0300
Subject: refactor: upload run form, lots of random shit

---
 frontend/src/App.tsx | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

(limited to 'frontend/src/App.tsx')

diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index d45cd97..095cbbe 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -10,6 +10,10 @@ import Games from './pages/Games';
 import Maps from './pages/Maps';
 import User from './pages/User';
 import Homepage from './pages/Homepage';
+import UploadRunDialog from './components/UploadRunDialog';
+import About from './pages/About';
+import { Game } from './types/Game';
+import { API } from './api/Api';
 import Maplist from './pages/Maplist';
 import Rankings from './pages/Rankings';
 
@@ -18,22 +22,44 @@ const App: React.FC = () => {
   const [profile, setProfile] = React.useState<UserProfile | undefined>(undefined);
   const [isModerator, setIsModerator] = React.useState<boolean>(true);
 
+  const [games, setGames] = React.useState<Game[]>([]);
+
+  const [uploadRunDialog, setUploadRunDialog] = React.useState<boolean>(false);
+  const [uploadRunDialogMapID, setUploadRunDialogMapID] = React.useState<number | undefined>(undefined);
+
   // React.useEffect(() => {
   //   if (token) {
   //     setIsModerator(JSON.parse(atob(token.split(".")[1])).mod)
   //   }
   // }, [token]);
 
+  const _fetch_games = async () => {
+    const games = await API.get_games();
+    setGames(games);
+  };
+
+  React.useEffect(() => {
+    _fetch_games();
+  }, []);
+
+  if (!games) {
+    return (
+      <></>
+    )
+  };
+
   return (
     <>
-      <Sidebar setToken={setToken} profile={profile} setProfile={setProfile} />
+      <UploadRunDialog open={uploadRunDialog} onClose={() => setUploadRunDialog(false)} mapID={uploadRunDialogMapID} games={games} />
+      <Sidebar setToken={setToken} profile={profile} setProfile={setProfile} onUploadRun={() => setUploadRunDialog(true)} />
       <Routes>
         <Route path="/" element={<Homepage />} />
         <Route path="/profile" element={<Profile profile={profile} />} />
         <Route path="/users/*" element={<User />} />
-        <Route path="/games" element={<Games />} />
-        <Route path="/maps/*" element={<Maps isModerator={isModerator} />} />
-        <Route path='/games/:id' element={<Maplist></Maplist>}></Route>
+        <Route path="/games" element={<Games games={games} />} />
+        <Route path='/games/:id' element={<Maplist />}></Route>
+        <Route path="/maps/*" element={<Maps profile={profile} isModerator={isModerator} onUploadRun={(mapID) => {setUploadRunDialog(true);setUploadRunDialogMapID(mapID)}} />}/>
+        <Route path="/about" element={<About />} />
         <Route path='/rankings' element={<Rankings></Rankings>}></Route>
         <Route path="*" element={"404"} />
       </Routes>
-- 
cgit v1.2.3

