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/components/UploadRunDialog.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/components/UploadRunDialog.tsx')
| -rw-r--r-- | frontend/src/components/UploadRunDialog.tsx | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx index 8081643..a0d23e7 100644 --- a/frontend/src/components/UploadRunDialog.tsx +++ b/frontend/src/components/UploadRunDialog.tsx | |||
| @@ -13,18 +13,15 @@ import useConfirm from '../hooks/UseConfirm'; | |||
| 13 | interface UploadRunDialogProps { | 13 | interface UploadRunDialogProps { |
| 14 | token?: string; | 14 | token?: string; |
| 15 | open: boolean; | 15 | open: boolean; |
| 16 | onClose: () => void; | 16 | onClose: (updateProfile: boolean) => void; |
| 17 | games: Game[]; | 17 | games: Game[]; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, games }) => { | 20 | const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, games }) => { |
| 21 | 21 | ||
| 22 | const [confirmMessage, setConfirmMessage] = React.useState<string>("Are you sure you want to upload this demo?"); | ||
| 23 | |||
| 24 | const { message, MessageDialogComponent } = useMessage(); | 22 | const { message, MessageDialogComponent } = useMessage(); |
| 25 | const { confirm, ConfirmDialogComponent } = useConfirm(); | 23 | const { confirm, ConfirmDialogComponent } = useConfirm(); |
| 26 | 24 | ||
| 27 | |||
| 28 | const navigate = useNavigate(); | 25 | const navigate = useNavigate(); |
| 29 | 26 | ||
| 30 | const [uploadRunContent, setUploadRunContent] = React.useState<UploadRunContent>({ | 27 | const [uploadRunContent, setUploadRunContent] = React.useState<UploadRunContent>({ |
| @@ -125,44 +122,41 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 125 | if (token) { | 122 | if (token) { |
| 126 | if (games[selectedGameID].is_coop) { | 123 | if (games[selectedGameID].is_coop) { |
| 127 | if (uploadRunContent.host_demo === null) { | 124 | if (uploadRunContent.host_demo === null) { |
| 128 | message("Error", "You must select a host demo to upload.") | 125 | await message("Error", "You must select a host demo to upload.") |
| 129 | return | 126 | return |
| 130 | } else if (uploadRunContent.partner_demo === null) { | 127 | } else if (uploadRunContent.partner_demo === null) { |
| 131 | message("Error", "You must select a partner demo to upload.") | 128 | await message("Error", "You must select a partner demo to upload.") |
| 132 | return | 129 | return |
| 133 | } | 130 | } |
| 134 | } else { | 131 | } else { |
| 135 | if (uploadRunContent.host_demo === null) { | 132 | if (uploadRunContent.host_demo === null) { |
| 136 | message("Error", "You must select a demo to upload.") | 133 | await message("Error", "You must select a demo to upload.") |
| 137 | return | 134 | return |
| 138 | } | 135 | } |
| 139 | } | 136 | } |
| 140 | const demo = SourceDemoParser.default() | 137 | const demo = SourceDemoParser.default() |
| 141 | .setOptions({ packets: true, header: true }) | 138 | .setOptions({ packets: true, header: true }) |
| 142 | .parse(await uploadRunContent.host_demo.arrayBuffer()); | 139 | .parse(await uploadRunContent.host_demo.arrayBuffer()); |
| 143 | const scoreboard = demo.findPacket<NetMessages.SvcUserMessage>((message) => { | 140 | const scoreboard = demo.findPacket<NetMessages.SvcUserMessage>((msg) => { |
| 144 | return message instanceof NetMessages.SvcUserMessage && message.userMessage instanceof ScoreboardTempUpdate; | 141 | return msg instanceof NetMessages.SvcUserMessage && msg.userMessage instanceof ScoreboardTempUpdate; |
| 145 | }) | 142 | }) |
| 146 | 143 | ||
| 147 | if (!scoreboard) { | 144 | if (!scoreboard) { |
| 148 | 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.") | 145 | 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.") |
| 149 | return | 146 | return |
| 150 | } | 147 | } |
| 151 | const { portalScore, timeScore } = scoreboard.userMessage?.as<ScoreboardTempUpdate>() ?? {}; | 148 | const { portalScore, timeScore } = scoreboard.userMessage?.as<ScoreboardTempUpdate>() ?? {}; |
| 152 | console.log(`Map Name: ${demo.mapName}. Portal Count: ${portalScore}. Ticks: ${timeScore}.`); | ||
| 153 | |||
| 154 | setConfirmMessage(`Map Name: ${demo.mapName}\nPortal Count: ${portalScore}\nTicks: ${timeScore}\n\nAre you sure you want to upload this demo?`) | ||
| 155 | 149 | ||
| 156 | const userConfirmed = await confirm("Upload demo?", confirmMessage); | 150 | 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?`); |
| 157 | 151 | ||
| 158 | if (!userConfirmed) { | 152 | if (!userConfirmed) { |
| 159 | return; | 153 | return; |
| 160 | } | 154 | } |
| 161 | 155 | ||
| 162 | const response = await API.post_record(token, uploadRunContent); | 156 | const [ success, response ] = await API.post_record(token, uploadRunContent); |
| 163 | await message("Message", response); | 157 | await message("Upload Record", response); |
| 164 | // navigate(0); | 158 | console.log("weweew") |
| 165 | onClose(); | 159 | onClose(success); |
| 166 | } | 160 | } |
| 167 | }; | 161 | }; |
| 168 | 162 | ||
| @@ -242,7 +236,7 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 242 | </div> | 236 | </div> |
| 243 | <div className='upload-run-buttons-container'> | 237 | <div className='upload-run-buttons-container'> |
| 244 | <button onClick={_upload_run}>Submit</button> | 238 | <button onClick={_upload_run}>Submit</button> |
| 245 | <button onClick={() => onClose()}>Cancel</button> | 239 | <button onClick={() => onClose(false)}>Cancel</button> |
| 246 | </div> | 240 | </div> |
| 247 | </div> | 241 | </div> |
| 248 | </> | 242 | </> |