aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/ModMenu.tsx
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-31 23:58:14 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-31 23:58:14 +0300
commitf5ad360d02303ce27a65e67feb8ae38f1e26742c (patch)
treeb3e5b0fde361223275b8cc91fe0ccbdbb945ed13 /frontend/src/components/ModMenu.tsx
parentbackend: remove auth check for viewing user page (diff)
downloadlphub-f5ad360d02303ce27a65e67feb8ae38f1e26742c.tar.gz
lphub-f5ad360d02303ce27a65e67feb8ae38f1e26742c.tar.bz2
lphub-f5ad360d02303ce27a65e67feb8ae38f1e26742c.zip
frontend: convert all native confirm and alerts to custom hooks
Diffstat (limited to 'frontend/src/components/ModMenu.tsx')
-rw-r--r--frontend/src/components/ModMenu.tsx16
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 @@
1import React from 'react'; 1import React from 'react';
2import ReactMarkdown from 'react-markdown'; 2import ReactMarkdown from 'react-markdown';
3import { useNavigate } from 'react-router-dom';
3 4
4import { MapSummary } from '../types/Map'; 5import { MapSummary } from '../types/Map';
5import { ModMenuContent } from '../types/Content'; 6import { ModMenuContent } from '../types/Content';
6import { API } from '../api/Api'; 7import { API } from '../api/Api';
7import "../css/ModMenu.css" 8import "../css/ModMenu.css"
8import { useNavigate } from 'react-router-dom'; 9import useConfirm from '../hooks/UseConfirm';
9 10
10interface ModMenuProps { 11interface ModMenuProps {
11 token?: string; 12 token?: string;
@@ -16,6 +17,8 @@ interface ModMenuProps {
16 17
17const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => { 18const 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>