diff options
Diffstat (limited to 'frontend/src/components/UploadRunDialog.tsx')
| -rw-r--r-- | frontend/src/components/UploadRunDialog.tsx | 103 |
1 files changed, 103 insertions, 0 deletions
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 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | import { UploadRunContent } from '../types/Content'; | ||
| 3 | |||
| 4 | import '../css/UploadRunDialog.css'; | ||
| 5 | import { Game } from '../types/Game'; | ||
| 6 | import Games from '../pages/Games'; | ||
| 7 | import { Map } from '../types/Map'; | ||
| 8 | import { API } from '../api/Api'; | ||
| 9 | |||
| 10 | interface UploadRunDialogProps { | ||
| 11 | open: boolean; | ||
| 12 | onClose: () => void; | ||
| 13 | mapID?: number; | ||
| 14 | games: Game[]; | ||
| 15 | } | ||
| 16 | |||
| 17 | const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ open, onClose, mapID, games }) => { | ||
| 18 | |||
| 19 | const [uploadRunContent, setUploadRunContent] = React.useState<UploadRunContent>({ | ||
| 20 | map_id: 0, | ||
| 21 | host_demo: null, | ||
| 22 | partner_demo: null, | ||
| 23 | partner_id: undefined, | ||
| 24 | is_partner_orange: undefined, | ||
| 25 | }); | ||
| 26 | |||
| 27 | const [selectedGameID, setSelectedGameID] = React.useState<number>(0); | ||
| 28 | const [selectedGameMaps, setSelectedGameMaps] = React.useState<Map[]>([]); | ||
| 29 | |||
| 30 | const [loading, setLoading] = React.useState<boolean>(false); | ||
| 31 | |||
| 32 | const _handle_game_select = async (game_id: string) => { | ||
| 33 | setLoading(true); | ||
| 34 | const gameMaps = await API.get_game_maps(game_id); | ||
| 35 | setSelectedGameMaps(gameMaps); | ||
| 36 | setUploadRunContent({ | ||
| 37 | ...uploadRunContent, | ||
| 38 | map_id: gameMaps[0].id, | ||
| 39 | }); | ||
| 40 | setSelectedGameID(parseInt(game_id) - 1); | ||
| 41 | setLoading(false); | ||
| 42 | }; | ||
| 43 | |||
| 44 | React.useEffect(() => { | ||
| 45 | _handle_game_select("1"); // a different approach? | ||
| 46 | }, []); | ||
| 47 | |||
| 48 | if (open) { | ||
| 49 | return ( | ||
| 50 | <> | ||
| 51 | <div id="upload-run-block" /> | ||
| 52 | <div id='upload-run-menu'> | ||
| 53 | <div id='upload-run-menu-add'> | ||
| 54 | <div id='upload-run-route-category'> | ||
| 55 | <span>Select Game</span> | ||
| 56 | <select onChange={(e) => _handle_game_select(e.target.value)}> | ||
| 57 | {games.map((game) => ( | ||
| 58 | <option key={game.id} value={game.id}>{game.name}</option> | ||
| 59 | ))} | ||
| 60 | </select> | ||
| 61 | { | ||
| 62 | !loading && | ||
| 63 | ( | ||
| 64 | <> | ||
| 65 | <span>Select Map</span> | ||
| 66 | <select onChange={(e) => setUploadRunContent({ | ||
| 67 | ...uploadRunContent, | ||
| 68 | map_id: parseInt(e.target.value), | ||
| 69 | })}> | ||
| 70 | {selectedGameMaps && selectedGameMaps.map((gameMap) => ( | ||
| 71 | <option key={gameMap.id} value={gameMap.id}>{gameMap.name}</option> | ||
| 72 | ))} | ||
| 73 | </select> | ||
| 74 | <span>Host Demo</span> | ||
| 75 | <input type="file" name="host_demo" id="host_demo" accept=".dem" /> | ||
| 76 | { | ||
| 77 | games[selectedGameID].is_coop && | ||
| 78 | ( | ||
| 79 | <> | ||
| 80 | <span>Partner Demo</span> | ||
| 81 | <input type="file" name="partner_demo" id="partner_demo" accept=".dem" /> | ||
| 82 | </> | ||
| 83 | ) | ||
| 84 | } | ||
| 85 | <button onClick={() => onClose()}>Submit</button> | ||
| 86 | <button onClick={() => onClose()}>Cancel</button> | ||
| 87 | </> | ||
| 88 | ) | ||
| 89 | } | ||
| 90 | </div> | ||
| 91 | </div> | ||
| 92 | </div> | ||
| 93 | </> | ||
| 94 | ); | ||
| 95 | } | ||
| 96 | |||
| 97 | return ( | ||
| 98 | <></> | ||
| 99 | ); | ||
| 100 | |||
| 101 | }; | ||
| 102 | |||
| 103 | export default UploadRunDialog; \ No newline at end of file | ||