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

