From 10b83e86efc11f2edb32af658986a558e4fccba7 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Wed, 30 Oct 2024 00:41:59 +0300 Subject: frontend: dont close demo upload on fail --- frontend/src/components/UploadRunDialog.tsx | 122 ++++++++++++++-------------- 1 file changed, 62 insertions(+), 60 deletions(-) (limited to 'frontend/src/components/UploadRunDialog.tsx') diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx index 22b895c..7a2efa1 100644 --- a/frontend/src/components/UploadRunDialog.tsx +++ b/frontend/src/components/UploadRunDialog.tsx @@ -54,39 +54,39 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, const fileInputRefPartner = React.useRef(null); const _handle_file_click = (host: boolean) => { - if (host) { - fileInputRef.current?.click(); - } else { - fileInputRefPartner.current?.click(); - } + if (host) { + fileInputRef.current?.click(); + } else { + fileInputRefPartner.current?.click(); + } } const _handle_drag_over = (e: React.DragEvent, host: boolean) => { - e.preventDefault(); - e.stopPropagation(); - if (host) { - setDragHighlight(true); - } else { - setDragHighlightPartner(true); - } + e.preventDefault(); + e.stopPropagation(); + if (host) { + setDragHighlight(true); + } else { + setDragHighlightPartner(true); + } } const _handle_drag_leave = (e: React.DragEvent, host: boolean) => { - e.preventDefault(); - e.stopPropagation(); - if (host) { - setDragHighlight(false); - } else { - setDragHighlightPartner(false); - } + e.preventDefault(); + e.stopPropagation(); + if (host) { + setDragHighlight(false); + } else { + setDragHighlightPartner(false); + } } const _handle_drop = (e: React.DragEvent, host: boolean) => { - e.preventDefault(); - e.stopPropagation(); - setDragHighlight(true); + e.preventDefault(); + e.stopPropagation(); + setDragHighlight(true); - _handle_file_change(e.dataTransfer.files, host); + _handle_file_change(e.dataTransfer.files, host); } const _handle_dropdowns = (dropdown: number) => { @@ -159,27 +159,29 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, return } const { portalScore, timeScore } = scoreboard.userMessage?.as() ?? {}; - + 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; } - messageLoad("Uploading..."); - const [ success, response ] = await API.post_record(token, uploadRunContent); - messageLoadClose(); + messageLoad("Uploading..."); + const [success, response] = await API.post_record(token, uploadRunContent); + messageLoadClose(); await message("Upload Record", response); - onClose(success); - navigate("/profile"); + if (success) { + onClose(success); + navigate("/profile"); + } } }; React.useEffect(() => { if (open) { - setDragHighlightPartner(false); - setDragHighlight(false); + setDragHighlightPartner(false); + setDragHighlight(false); _handle_game_select("1", "Portal 2 - Singleplayer"); // a different approach?. } }, [open]); @@ -189,9 +191,9 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, <>
{MessageDialogComponent} - {MessageDialogLoadComponent} + {MessageDialogLoadComponent} {ConfirmDialogComponent} - +
@@ -227,38 +229,38 @@ const UploadRunDialog: React.FC = ({ token, open, onClose,
Host Demo -
{_handle_file_click(true)}} onDragOver={(e) => {_handle_drag_over(e, true)}} onDrop={(e) => {_handle_drop(e, true)}} onDragLeave={(e) => {_handle_drag_leave(e, true)}} className={`upload-run-drag-area ${dragHightlight ? "upload-run-drag-area-highlight" : ""} ${uploadRunContent.host_demo ? "upload-run-drag-area-hidden" : ""}`}> - _handle_file_change(e.target.files, true)} /> - {!uploadRunContent.host_demo ? -
- Drag and drop -
- Or click here
- -
-
- : null} - - {uploadRunContent.host_demo?.name} -
+
{ _handle_file_click(true) }} onDragOver={(e) => { _handle_drag_over(e, true) }} onDrop={(e) => { _handle_drop(e, true) }} onDragLeave={(e) => { _handle_drag_leave(e, true) }} className={`upload-run-drag-area ${dragHightlight ? "upload-run-drag-area-highlight" : ""} ${uploadRunContent.host_demo ? "upload-run-drag-area-hidden" : ""}`}> + _handle_file_change(e.target.files, true)} /> + {!uploadRunContent.host_demo ? +
+ Drag and drop +
+ Or click here
+ +
+
+ : null} + + {uploadRunContent.host_demo?.name} +
{ games[selectedGameID].is_coop && ( <> Partner Demo -
{_handle_file_click(false)}} onDragOver={(e) => {_handle_drag_over(e, false)}} onDrop={(e) => {_handle_drop(e, false)}} onDragLeave={(e) => {_handle_drag_leave(e, false)}} className={`upload-run-drag-area ${dragHightlightPartner ? "upload-run-drag-area-highlight-partner" : ""} ${uploadRunContent.partner_demo ? "upload-run-drag-area-hidden" : ""}`}> - _handle_file_change(e.target.files, false)} /> {!uploadRunContent.partner_demo ? -
- Drag and drop -
- Or click here
- -
-
- : null} - - {uploadRunContent.partner_demo?.name} -
+
{ _handle_file_click(false) }} onDragOver={(e) => { _handle_drag_over(e, false) }} onDrop={(e) => { _handle_drop(e, false) }} onDragLeave={(e) => { _handle_drag_leave(e, false) }} className={`upload-run-drag-area ${dragHightlightPartner ? "upload-run-drag-area-highlight-partner" : ""} ${uploadRunContent.partner_demo ? "upload-run-drag-area-hidden" : ""}`}> + _handle_file_change(e.target.files, false)} /> {!uploadRunContent.partner_demo ? +
+ Drag and drop +
+ Or click here
+ +
+
+ : null} + + {uploadRunContent.partner_demo?.name} +
) } -- cgit v1.2.3