From 53337bad0623a5f32c87d760bc03efb3cfe4eab6 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:06:15 +0300 Subject: feat/frontend: remove map select from upload run dialog (#239) --- frontend/src/components/UploadRunDialog.tsx | 113 +++++++++++++--------------- 1 file changed, 52 insertions(+), 61 deletions(-) (limited to 'frontend/src/components') diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx index 118b589..c02fdb8 100644 --- a/frontend/src/components/UploadRunDialog.tsx +++ b/frontend/src/components/UploadRunDialog.tsx @@ -4,12 +4,12 @@ import { ScoreboardTempUpdate, SourceDemoParser, NetMessages } from '@nekz/sdp'; import '@css/UploadRunDialog.css'; import { Game } from '@customTypes/Game'; -import { Map } from '@customTypes/Map'; import { API } from '@api/Api'; import { useNavigate } from 'react-router-dom'; import useMessage from '@hooks/UseMessage'; import useConfirm from '@hooks/UseConfirm'; import useMessageLoad from "@hooks/UseMessageLoad"; +import { MapNames } from '@customTypes/MapNames'; interface UploadRunDialogProps { token?: string; @@ -27,19 +27,11 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, const navigate = useNavigate(); const [uploadRunContent, setUploadRunContent] = React.useState({ - map_id: 0, host_demo: null, partner_demo: null, }); - const [currentMap, setCurrentMap] = React.useState(""); - - const _set_current_map = (game_name: string) => { - setCurrentMap(game_name); - } - const [selectedGameID, setSelectedGameID] = React.useState(0); - const [selectedGameMaps, setSelectedGameMaps] = React.useState([]); const [selectedGameName, setSelectedGameName] = React.useState(""); // dropdowns @@ -50,6 +42,7 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, const [dragHightlight, setDragHighlight] = React.useState(false); const [dragHightlightPartner, setDragHighlightPartner] = React.useState(false); + const fileInputRef = React.useRef(null); const fileInputRefPartner = React.useRef(null); @@ -102,14 +95,6 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, const _handle_game_select = async (game_id: string, game_name: string) => { setLoading(true); - const gameMaps = await API.get_game_maps(game_id); - setSelectedGameMaps(gameMaps); - setUploadRunContent({ - map_id: gameMaps.find((map) => !map.is_disabled)!.id, //gameMaps[0].id, - host_demo: null, - partner_demo: null, - }); - _set_current_map(gameMaps.find((map) => !map.is_disabled)!.name); setSelectedGameID(parseInt(game_id) - 1); setSelectedGameName(game_name); setLoading(false); @@ -158,6 +143,20 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, 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 } + + if (!demo.mapName || !MapNames[demo.mapName]) { + await message("Error", "Error while processing demo: Invalid map name.") + return + } + + if (selectedGameID === 0 && MapNames[demo.mapName] > 60) { + await message("Error", "Error while processing demo: Invalid cooperative demo in singleplayer submission.") + return + } else if (selectedGameID === 1 && MapNames[demo.mapName] <= 60) { + await message("Error", "Error while processing demo: Invalid singleplayer demo in cooperative submission.") + 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?`); @@ -167,10 +166,14 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, } messageLoad("Uploading..."); - const [success, response] = await API.post_record(token, uploadRunContent); + const [success, response] = await API.post_record(token, uploadRunContent, MapNames[demo.mapName]); messageLoadClose(); await message("Upload Record", response); if (success) { + setUploadRunContent({ + host_demo: null, + partner_demo: null, + }); onClose(success); navigate("/profile"); } @@ -179,7 +182,6 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, React.useEffect(() => { if (open) { - setDragHighlightPartner(false); setDragHighlight(false); _handle_game_select("1", "Portal 2 - Singleplayer"); // a different approach?. @@ -203,37 +205,20 @@ const UploadRunDialog: React.FC = ({ token, open, onClose,
{selectedGameName}
-
+
{games.map((game) => (
{ _handle_game_select(game.id.toString(), game.name); _handle_dropdowns(1) }} key={game.id}>{game.name}
))}
- {!loading && ( - <> -
-

Select Map

-
_handle_dropdowns(2)} style={{ display: "flex", alignItems: "center", cursor: "pointer", justifyContent: "space-between", margin: "10px 0px" }}> - {currentMap} - -
-
- - - - )} -
+ { !loading && ( <> - -
-

Host Demo

+ +
+

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 ? @@ -252,38 +237,44 @@ const UploadRunDialog: React.FC = ({ token, open, onClose, 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 +
+

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 ?
- Or click here
- + Drag and drop +
+ Or click here
+ +
-
- : null} + : null} - {uploadRunContent.partner_demo?.name} + {uploadRunContent.partner_demo?.name} +
-
) } -
-
+
+
+ +
-
- ) }
-
- - -
+
+ + +
-- cgit v1.2.3