From 89560a61bc6e41d86acaea596762eda2da38fe50 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:29:42 +0300 Subject: refactor: upload run form, lots of random shit --- frontend/src/components/UploadRunDialog.tsx | 103 ++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 frontend/src/components/UploadRunDialog.tsx (limited to 'frontend/src/components/UploadRunDialog.tsx') diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx new file mode 100644 index 0000000..e099a40 --- /dev/null +++ b/frontend/src/components/UploadRunDialog.tsx @@ -0,0 +1,103 @@ +import React from 'react'; +import { UploadRunContent } from '../types/Content'; + +import '../css/UploadRunDialog.css'; +import { Game } from '../types/Game'; +import Games from '../pages/Games'; +import { Map } from '../types/Map'; +import { API } from '../api/Api'; + +interface UploadRunDialogProps { + open: boolean; + onClose: () => void; + mapID?: number; + games: Game[]; +} + +const UploadRunDialog: React.FC = ({ open, onClose, mapID, games }) => { + + const [uploadRunContent, setUploadRunContent] = React.useState({ + map_id: 0, + host_demo: null, + partner_demo: null, + partner_id: undefined, + is_partner_orange: undefined, + }); + + const [selectedGameID, setSelectedGameID] = React.useState(0); + const [selectedGameMaps, setSelectedGameMaps] = React.useState([]); + + const [loading, setLoading] = React.useState(false); + + const _handle_game_select = async (game_id: string) => { + setLoading(true); + const gameMaps = await API.get_game_maps(game_id); + setSelectedGameMaps(gameMaps); + setUploadRunContent({ + ...uploadRunContent, + map_id: gameMaps[0].id, + }); + setSelectedGameID(parseInt(game_id) - 1); + setLoading(false); + }; + + React.useEffect(() => { + _handle_game_select("1"); // a different approach? + }, []); + + if (open) { + return ( + <> +
+
+
+
+ Select Game + + { + !loading && + ( + <> + Select Map + + Host Demo + + { + games[selectedGameID].is_coop && + ( + <> + Partner Demo + + + ) + } + + + + ) + } +
+
+
+ + ); + } + + return ( + <> + ); + +}; + +export default UploadRunDialog; \ No newline at end of file -- cgit v1.2.3