diff options
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/src/components/UploadRunDialog.tsx | 22 | ||||
| -rw-r--r-- | frontend/src/hooks/UseConfirm.tsx | 2 | ||||
| -rw-r--r-- | frontend/src/hooks/UseMessage.tsx | 8 | ||||
| -rw-r--r-- | frontend/src/pages/Profile.tsx | 6 |
4 files changed, 19 insertions, 19 deletions
diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx index 0476d6f..a1bebd6 100644 --- a/frontend/src/components/UploadRunDialog.tsx +++ b/frontend/src/components/UploadRunDialog.tsx | |||
| @@ -19,12 +19,9 @@ interface UploadRunDialogProps { | |||
| 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>({ |
| @@ -95,42 +92,39 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 95 | if (token) { | 92 | if (token) { |
| 96 | if (games[selectedGameID].is_coop) { | 93 | if (games[selectedGameID].is_coop) { |
| 97 | if (uploadRunContent.host_demo === null) { | 94 | if (uploadRunContent.host_demo === null) { |
| 98 | message("Error", "You must select a host demo to upload.") | 95 | await message("Error", "You must select a host demo to upload.") |
| 99 | return | 96 | return |
| 100 | } else if (uploadRunContent.partner_demo === null) { | 97 | } else if (uploadRunContent.partner_demo === null) { |
| 101 | message("Error", "You must select a partner demo to upload.") | 98 | await message("Error", "You must select a partner demo to upload.") |
| 102 | return | 99 | return |
| 103 | } | 100 | } |
| 104 | } else { | 101 | } else { |
| 105 | if (uploadRunContent.host_demo === null) { | 102 | if (uploadRunContent.host_demo === null) { |
| 106 | message("Error", "You must select a demo to upload.") | 103 | await message("Error", "You must select a demo to upload.") |
| 107 | return | 104 | return |
| 108 | } | 105 | } |
| 109 | } | 106 | } |
| 110 | const demo = SourceDemoParser.default() | 107 | const demo = SourceDemoParser.default() |
| 111 | .setOptions({ packets: true, header: true }) | 108 | .setOptions({ packets: true, header: true }) |
| 112 | .parse(await uploadRunContent.host_demo.arrayBuffer()); | 109 | .parse(await uploadRunContent.host_demo.arrayBuffer()); |
| 113 | const scoreboard = demo.findPacket<NetMessages.SvcUserMessage>((message) => { | 110 | const scoreboard = demo.findPacket<NetMessages.SvcUserMessage>((msg) => { |
| 114 | return message instanceof NetMessages.SvcUserMessage && message.userMessage instanceof ScoreboardTempUpdate; | 111 | return msg instanceof NetMessages.SvcUserMessage && msg.userMessage instanceof ScoreboardTempUpdate; |
| 115 | }) | 112 | }) |
| 116 | 113 | ||
| 117 | if (!scoreboard) { | 114 | if (!scoreboard) { |
| 118 | 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.") | 115 | 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.") |
| 119 | return | 116 | return |
| 120 | } | 117 | } |
| 121 | const { portalScore, timeScore } = scoreboard.userMessage?.as<ScoreboardTempUpdate>() ?? {}; | 118 | const { portalScore, timeScore } = scoreboard.userMessage?.as<ScoreboardTempUpdate>() ?? {}; |
| 122 | console.log(`Map Name: ${demo.mapName}. Portal Count: ${portalScore}. Ticks: ${timeScore}.`); | ||
| 123 | |||
| 124 | setConfirmMessage(`Map Name: ${demo.mapName}\nPortal Count: ${portalScore}\nTicks: ${timeScore}\n\nAre you sure you want to upload this demo?`) | ||
| 125 | 119 | ||
| 126 | const userConfirmed = await confirm("Upload demo?", confirmMessage); | 120 | 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?`); |
| 127 | 121 | ||
| 128 | if (!userConfirmed) { | 122 | if (!userConfirmed) { |
| 129 | return; | 123 | return; |
| 130 | } | 124 | } |
| 131 | 125 | ||
| 132 | const response = await API.post_record(token, uploadRunContent); | 126 | const response = await API.post_record(token, uploadRunContent); |
| 133 | message("Message", response); | 127 | await message("Upload Record", response); |
| 134 | // navigate(0); | 128 | // navigate(0); |
| 135 | onClose(); | 129 | onClose(); |
| 136 | } | 130 | } |
diff --git a/frontend/src/hooks/UseConfirm.tsx b/frontend/src/hooks/UseConfirm.tsx index 80a0d51..9a7853b 100644 --- a/frontend/src/hooks/UseConfirm.tsx +++ b/frontend/src/hooks/UseConfirm.tsx | |||
| @@ -3,9 +3,9 @@ import ConfirmDialog from '../components/ConfirmDialog'; | |||
| 3 | 3 | ||
| 4 | const useConfirm = () => { | 4 | const useConfirm = () => { |
| 5 | const [isOpen, setIsOpen] = useState(false); | 5 | const [isOpen, setIsOpen] = useState(false); |
| 6 | const [resolvePromise, setResolvePromise] = useState<((value: boolean) => void) | null>(null); | ||
| 7 | const [title, setTitle] = useState<string>(""); | 6 | const [title, setTitle] = useState<string>(""); |
| 8 | const [subtitle, setSubtitle] = useState<string>(""); | 7 | const [subtitle, setSubtitle] = useState<string>(""); |
| 8 | const [resolvePromise, setResolvePromise] = useState<((value: boolean) => void) | null>(null); | ||
| 9 | 9 | ||
| 10 | const confirm = ( titleN: string, subtitleN: string ) => { | 10 | const confirm = ( titleN: string, subtitleN: string ) => { |
| 11 | setIsOpen(true); | 11 | setIsOpen(true); |
diff --git a/frontend/src/hooks/UseMessage.tsx b/frontend/src/hooks/UseMessage.tsx index 249a3bf..0d2799c 100644 --- a/frontend/src/hooks/UseMessage.tsx +++ b/frontend/src/hooks/UseMessage.tsx | |||
| @@ -3,18 +3,24 @@ import MessageDialog from "../components/MessageDialog"; | |||
| 3 | 3 | ||
| 4 | const useMessage = () => { | 4 | const useMessage = () => { |
| 5 | const [isOpen, setIsOpen] = useState(false); | 5 | const [isOpen, setIsOpen] = useState(false); |
| 6 | |||
| 7 | const [title, setTitle] = useState<string>(""); | 6 | const [title, setTitle] = useState<string>(""); |
| 8 | const [subtitle, setSubtitle] = useState<string>(""); | 7 | const [subtitle, setSubtitle] = useState<string>(""); |
| 8 | const [resolvePromise, setResolvePromise] = useState<(() => void) | null>(null); | ||
| 9 | 9 | ||
| 10 | const message = (title: string, subtitle: string) => { | 10 | const message = (title: string, subtitle: string) => { |
| 11 | setIsOpen(true); | 11 | setIsOpen(true); |
| 12 | setTitle(title); | 12 | setTitle(title); |
| 13 | setSubtitle(subtitle); | 13 | setSubtitle(subtitle); |
| 14 | return new Promise<void>((resolve) => { | ||
| 15 | setResolvePromise(() => resolve); | ||
| 16 | }) | ||
| 14 | }; | 17 | }; |
| 15 | 18 | ||
| 16 | const handleClose = () => { | 19 | const handleClose = () => { |
| 17 | setIsOpen(false); | 20 | setIsOpen(false); |
| 21 | if (resolvePromise) { | ||
| 22 | setResolvePromise(null); | ||
| 23 | } | ||
| 18 | }; | 24 | }; |
| 19 | 25 | ||
| 20 | const MessageDialogComponent = isOpen && ( | 26 | const MessageDialogComponent = isOpen && ( |
diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index 7559c77..05f372e 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx | |||
| @@ -63,7 +63,7 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | const _delete_submission = async (map_id: number, record_id: number) => { | 65 | const _delete_submission = async (map_id: number, record_id: number) => { |
| 66 | const userConfirmed = await confirm("Delete record?", "This action cannot be undone"); | 66 | const userConfirmed = await confirm("Delete Record", "Are you sure you want to delete this record?"); |
| 67 | 67 | ||
| 68 | if (!userConfirmed) { | 68 | if (!userConfirmed) { |
| 69 | return; | 69 | return; |
| @@ -71,9 +71,9 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 71 | 71 | ||
| 72 | const api_success = await API.delete_map_record(token!, map_id, record_id); | 72 | const api_success = await API.delete_map_record(token!, map_id, record_id); |
| 73 | if (api_success) { | 73 | if (api_success) { |
| 74 | message("Success", "Successfully deleted record"); | 74 | await message("Delete Record", "Successfully deleted record."); |
| 75 | } else { | 75 | } else { |
| 76 | message("Error", "Could not delete record"); | 76 | await message("Delete Record", "Could not delete record."); |
| 77 | } | 77 | } |
| 78 | }; | 78 | }; |
| 79 | 79 | ||