diff options
Diffstat (limited to 'frontend/src/components/ModMenu.tsx')
| -rw-r--r-- | frontend/src/components/ModMenu.tsx | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/frontend/src/components/ModMenu.tsx b/frontend/src/components/ModMenu.tsx index 5b0d1c8..2fb1737 100644 --- a/frontend/src/components/ModMenu.tsx +++ b/frontend/src/components/ModMenu.tsx | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | import React from 'react'; | 1 | import React from 'react'; |
| 2 | import ReactMarkdown from 'react-markdown'; | 2 | import ReactMarkdown from 'react-markdown'; |
| 3 | import { useNavigate } from 'react-router-dom'; | ||
| 3 | 4 | ||
| 4 | import { MapSummary } from '../types/Map'; | 5 | import { MapSummary } from '../types/Map'; |
| 5 | import { ModMenuContent } from '../types/Content'; | 6 | import { ModMenuContent } from '../types/Content'; |
| 6 | import { API } from '../api/Api'; | 7 | import { API } from '../api/Api'; |
| 7 | import "../css/ModMenu.css" | 8 | import "../css/ModMenu.css" |
| 8 | import { useNavigate } from 'react-router-dom'; | 9 | import useConfirm from '../hooks/UseConfirm'; |
| 9 | 10 | ||
| 10 | interface ModMenuProps { | 11 | interface ModMenuProps { |
| 11 | token?: string; | 12 | token?: string; |
| @@ -16,6 +17,8 @@ interface ModMenuProps { | |||
| 16 | 17 | ||
| 17 | const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => { | 18 | const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => { |
| 18 | 19 | ||
| 20 | const { confirm, ConfirmDialogComponent } = useConfirm(); | ||
| 21 | |||
| 19 | const [menu, setMenu] = React.useState<number>(0); | 22 | const [menu, setMenu] = React.useState<number>(0); |
| 20 | const [showButton, setShowButton] = React.useState<boolean>(true); | 23 | const [showButton, setShowButton] = React.useState<boolean>(true); |
| 21 | 24 | ||
| @@ -64,7 +67,7 @@ const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => | |||
| 64 | }; | 67 | }; |
| 65 | 68 | ||
| 66 | const _edit_map_summary_image = async () => { | 69 | const _edit_map_summary_image = async () => { |
| 67 | if (window.confirm("Are you sure you want to submit this to the database?")) { | 70 | if (await confirm("Edit Map Summary Image", "Are you sure you want to submit this to the database?")) { |
| 68 | if (token) { | 71 | if (token) { |
| 69 | const success = await API.put_map_image(token, mapID, image); | 72 | const success = await API.put_map_image(token, mapID, image); |
| 70 | if (success) { | 73 | if (success) { |
| @@ -77,7 +80,7 @@ const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => | |||
| 77 | }; | 80 | }; |
| 78 | 81 | ||
| 79 | const _edit_map_summary_route = async () => { | 82 | const _edit_map_summary_route = async () => { |
| 80 | if (window.confirm("Are you sure you want to submit this to the database?")) { | 83 | if (await confirm("Edit Map Summary Route", "Are you sure you want to submit this to the database?")) { |
| 81 | if (token) { | 84 | if (token) { |
| 82 | routeContent.date += "T00:00:00Z"; | 85 | routeContent.date += "T00:00:00Z"; |
| 83 | const success = await API.put_map_summary(token, mapID, routeContent); | 86 | const success = await API.put_map_summary(token, mapID, routeContent); |
| @@ -91,7 +94,7 @@ const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => | |||
| 91 | }; | 94 | }; |
| 92 | 95 | ||
| 93 | const _create_map_summary_route = async () => { | 96 | const _create_map_summary_route = async () => { |
| 94 | if (window.confirm("Are you sure you want to submit this to the database?")) { | 97 | if (await confirm("Create Map Summary Route", "Are you sure you want to submit this to the database?")) { |
| 95 | if (token) { | 98 | if (token) { |
| 96 | routeContent.date += "T00:00:00Z"; | 99 | routeContent.date += "T00:00:00Z"; |
| 97 | const success = await API.post_map_summary(token, mapID, routeContent); | 100 | const success = await API.post_map_summary(token, mapID, routeContent); |
| @@ -105,8 +108,8 @@ const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => | |||
| 105 | }; | 108 | }; |
| 106 | 109 | ||
| 107 | const _delete_map_summary_route = async () => { | 110 | const _delete_map_summary_route = async () => { |
| 108 | if (window.confirm(`Are you sure you want to delete this run from the database? | 111 | if (await confirm("Delete Map Summary Route", `Are you sure you want to submit this to the database?\n |
| 109 | ${data.summary.routes[selectedRun].category.name} ${data.summary.routes[selectedRun].history.score_count} portals ${data.summary.routes[selectedRun].history.runner_name}`)) { | 112 | ${data.summary.routes[selectedRun].category.name}\n${data.summary.routes[selectedRun].history.score_count} portals\n${data.summary.routes[selectedRun].history.runner_name}`)) { |
| 110 | if (token) { | 113 | if (token) { |
| 111 | const success = await API.delete_map_summary(token, mapID, data.summary.routes[selectedRun].route_id); | 114 | const success = await API.delete_map_summary(token, mapID, data.summary.routes[selectedRun].route_id); |
| 112 | if (success) { | 115 | if (success) { |
| @@ -160,6 +163,7 @@ const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => | |||
| 160 | 163 | ||
| 161 | return ( | 164 | return ( |
| 162 | <> | 165 | <> |
| 166 | {ConfirmDialogComponent} | ||
| 163 | <div id="modview_block" /> | 167 | <div id="modview_block" /> |
| 164 | <div id='modview'> | 168 | <div id='modview'> |
| 165 | <div> | 169 | <div> |