From 3ee18a8cb3a2893f552275c35b0724daf4b8ab69 Mon Sep 17 00:00:00 2001
From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>
Date: Tue, 22 Oct 2024 12:23:35 +0300
Subject: frontend: await message

---
 frontend/src/components/UploadRunDialog.tsx | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

(limited to 'frontend/src/components/UploadRunDialog.tsx')

diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx
index 0476d6f..a1bebd6 100644
--- a/frontend/src/components/UploadRunDialog.tsx
+++ b/frontend/src/components/UploadRunDialog.tsx
@@ -19,12 +19,9 @@ interface UploadRunDialogProps {
 
 const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, games }) => {
 
-  const [confirmMessage, setConfirmMessage] = React.useState<string>("Are you sure you want to upload this demo?");
-
   const { message, MessageDialogComponent } = useMessage();
   const { confirm, ConfirmDialogComponent } = useConfirm();
 
-
   const navigate = useNavigate();
 
   const [uploadRunContent, setUploadRunContent] = React.useState<UploadRunContent>({
@@ -95,42 +92,39 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose,
     if (token) {
       if (games[selectedGameID].is_coop) {
         if (uploadRunContent.host_demo === null) {
-          message("Error", "You must select a host demo to upload.")
+          await message("Error", "You must select a host demo to upload.")
           return
         } else if (uploadRunContent.partner_demo === null) {
-          message("Error", "You must select a partner demo to upload.")
+          await message("Error", "You must select a partner demo to upload.")
           return
         }
       } else {
         if (uploadRunContent.host_demo === null) {
-          message("Error", "You must select a demo to upload.")
+          await message("Error", "You must select a demo to upload.")
           return
         }
       }
       const demo = SourceDemoParser.default()
         .setOptions({ packets: true, header: true })
         .parse(await uploadRunContent.host_demo.arrayBuffer());
-      const scoreboard = demo.findPacket<NetMessages.SvcUserMessage>((message) => {
-        return message instanceof NetMessages.SvcUserMessage && message.userMessage instanceof ScoreboardTempUpdate;
+      const scoreboard = demo.findPacket<NetMessages.SvcUserMessage>((msg) => {
+        return msg instanceof NetMessages.SvcUserMessage && msg.userMessage instanceof ScoreboardTempUpdate;
       })
 
       if (!scoreboard) {
-        message("Error", "Error while processing demo: Unable to get scoreboard result. Either there is a demo that is corrupt or haven't been recorded in challenge mode.")
+        await message("Error", "Error while processing demo: Unable to get scoreboard result. Either there is a demo that is corrupt or haven't been recorded in challenge mode.")
         return
       }
       const { portalScore, timeScore } = scoreboard.userMessage?.as<ScoreboardTempUpdate>() ?? {};
-      console.log(`Map Name: ${demo.mapName}. Portal Count: ${portalScore}. Ticks: ${timeScore}.`);
-
-      setConfirmMessage(`Map Name: ${demo.mapName}\nPortal Count: ${portalScore}\nTicks: ${timeScore}\n\nAre you sure you want to upload this demo?`)
       
-      const userConfirmed = await confirm("Upload demo?", confirmMessage);
+      const userConfirmed = await confirm("Upload Record", `Map Name: ${demo.mapName}\nPortal Count: ${portalScore}\nTicks: ${timeScore}\n\nAre you sure you want to upload this demo?`);
 
       if (!userConfirmed) {
         return;
       }
 
       const response = await API.post_record(token, uploadRunContent);
-      message("Message", response);
+      await message("Upload Record", response);
       // navigate(0);
       onClose();
     }
-- 
cgit v1.2.3


From c5154b2203342280a0cf75bb5f25311e6112400e Mon Sep 17 00:00:00 2001
From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>
Date: Tue, 22 Oct 2024 12:41:44 +0300
Subject: frontend: update profile after upload run

---
 frontend/src/App.tsx                        | 7 ++++++-
 frontend/src/api/Maps.tsx                   | 4 ++--
 frontend/src/components/UploadRunDialog.tsx | 9 ++++-----
 3 files changed, 12 insertions(+), 8 deletions(-)

(limited to 'frontend/src/components/UploadRunDialog.tsx')

diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index d1d501d..6953de9 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -81,7 +81,6 @@ const App: React.FC = () => {
 
   return (
     <>
-      <UploadRunDialog token={token} open={uploadRunDialog} onClose={() => setUploadRunDialog(false)} games={games} />
       <Sidebar setToken={setToken} profile={profile} setProfile={setProfile} onUploadRun={() => setUploadRunDialog(true)} />
       <Routes>
         <Route path="/" element={<Homepage />} />
@@ -95,6 +94,12 @@ const App: React.FC = () => {
         <Route path='/rankings' element={<Rankings />}></Route>
         <Route path="*" element={"404"} />
       </Routes>
+      <UploadRunDialog token={token} open={uploadRunDialog} onClose={(updateProfile) => {
+        setUploadRunDialog(false);
+        if (token) {
+          _set_profile(get_user_id_from_token(token));
+        }
+      }} games={games} />
     </>
   );
 };
diff --git a/frontend/src/api/Maps.tsx b/frontend/src/api/Maps.tsx
index 2209788..e57fc45 100644
--- a/frontend/src/api/Maps.tsx
+++ b/frontend/src/api/Maps.tsx
@@ -75,7 +75,7 @@ export const delete_map_discussion = async (token: string, map_id: string, discu
   return response.data.success;
 };
 
-export const post_record = async (token: string, run: UploadRunContent): Promise<string> => {
+export const post_record = async (token: string, run: UploadRunContent): Promise<[boolean, string]> => {
   if (run.partner_demo) {
     const response = await axios.postForm(url(`maps/${run.map_id}/record`), {
       "host_demo": run.host_demo,
@@ -94,7 +94,7 @@ export const post_record = async (token: string, run: UploadRunContent): Promise
         "Authorization": token,
       }
     });
-    return response.data.message;
+    return [ response.data.success, response.data.message ];
   }
 }
 
diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx
index a1bebd6..b39aab6 100644
--- a/frontend/src/components/UploadRunDialog.tsx
+++ b/frontend/src/components/UploadRunDialog.tsx
@@ -13,7 +13,7 @@ import useConfirm from '../hooks/UseConfirm';
 interface UploadRunDialogProps {
   token?: string;
   open: boolean;
-  onClose: () => void;
+  onClose: (updateProfile: boolean) => void;
   games: Game[];
 }
 
@@ -123,10 +123,9 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose,
         return;
       }
 
-      const response = await API.post_record(token, uploadRunContent);
+      const [ success, response ] = await API.post_record(token, uploadRunContent);
       await message("Upload Record", response);
-      // navigate(0);
-      onClose();
+      onClose(success);
     }
   };
 
@@ -193,7 +192,7 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose,
                       </div>
                       <div className='upload-run-buttons-container'>
                         <button onClick={_upload_run}>Submit</button>
-                        <button onClick={() => onClose()}>Cancel</button>
+                        <button onClick={() => onClose(false)}>Cancel</button>
                       </div>
                     </div>
                   </>
-- 
cgit v1.2.3


From f47d137b41e90d4ecc541d7de49eed52ec44c091 Mon Sep 17 00:00:00 2001
From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>
Date: Tue, 22 Oct 2024 13:25:48 +0300
Subject: frontend: update profile after upload run

---
 frontend/src/components/UploadRunDialog.tsx | 1 +
 1 file changed, 1 insertion(+)

(limited to 'frontend/src/components/UploadRunDialog.tsx')

diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx
index b39aab6..d0b5687 100644
--- a/frontend/src/components/UploadRunDialog.tsx
+++ b/frontend/src/components/UploadRunDialog.tsx
@@ -125,6 +125,7 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose,
 
       const [ success, response ] = await API.post_record(token, uploadRunContent);
       await message("Upload Record", response);
+      console.log("weweew")
       onClose(success);
     }
   };
-- 
cgit v1.2.3

