aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/ModMenu.tsx
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-09 16:34:12 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-09 16:34:12 +0300
commita7c282ca348c1e8e60559e5c064caee28ba11eec (patch)
tree43bd7bdb2bbc80b92b96a14b36c33f0b7df622c9 /frontend/src/components/ModMenu.tsx
parentRankings page (diff)
downloadlphub-a7c282ca348c1e8e60559e5c064caee28ba11eec.tar.gz
lphub-a7c282ca348c1e8e60559e5c064caee28ba11eec.tar.bz2
lphub-a7c282ca348c1e8e60559e5c064caee28ba11eec.zip
refactor: so much shit
Diffstat (limited to 'frontend/src/components/ModMenu.tsx')
-rw-r--r--frontend/src/components/ModMenu.tsx44
1 files changed, 39 insertions, 5 deletions
diff --git a/frontend/src/components/ModMenu.tsx b/frontend/src/components/ModMenu.tsx
index a0945eb..5b0d1c8 100644
--- a/frontend/src/components/ModMenu.tsx
+++ b/frontend/src/components/ModMenu.tsx
@@ -5,14 +5,16 @@ import { MapSummary } from '../types/Map';
5import { ModMenuContent } from '../types/Content'; 5import { ModMenuContent } from '../types/Content';
6import { API } from '../api/Api'; 6import { API } from '../api/Api';
7import "../css/ModMenu.css" 7import "../css/ModMenu.css"
8import { useNavigate } from 'react-router-dom';
8 9
9interface ModMenuProps { 10interface ModMenuProps {
11 token?: string;
10 data: MapSummary; 12 data: MapSummary;
11 selectedRun: number; 13 selectedRun: number;
12 mapID: string; 14 mapID: string;
13} 15}
14 16
15const ModMenu: React.FC<ModMenuProps> = ({ data, selectedRun, mapID }) => { 17const ModMenu: React.FC<ModMenuProps> = ({ token, data, selectedRun, mapID }) => {
16 18
17 const [menu, setMenu] = React.useState<number>(0); 19 const [menu, setMenu] = React.useState<number>(0);
18 const [showButton, setShowButton] = React.useState<boolean>(true); 20 const [showButton, setShowButton] = React.useState<boolean>(true);
@@ -30,6 +32,8 @@ const ModMenu: React.FC<ModMenuProps> = ({ data, selectedRun, mapID }) => {
30 const [image, setImage] = React.useState<string>(""); 32 const [image, setImage] = React.useState<string>("");
31 const [md, setMd] = React.useState<string>(""); 33 const [md, setMd] = React.useState<string>("");
32 34
35 const navigate = useNavigate();
36
33 function compressImage(file: File): Promise<string> { 37 function compressImage(file: File): Promise<string> {
34 const reader = new FileReader(); 38 const reader = new FileReader();
35 reader.readAsDataURL(file); 39 reader.readAsDataURL(file);
@@ -61,26 +65,56 @@ const ModMenu: React.FC<ModMenuProps> = ({ data, selectedRun, mapID }) => {
61 65
62 const _edit_map_summary_image = async () => { 66 const _edit_map_summary_image = async () => {
63 if (window.confirm("Are you sure you want to submit this to the database?")) { 67 if (window.confirm("Are you sure you want to submit this to the database?")) {
64 await API.put_map_image(mapID, image); 68 if (token) {
69 const success = await API.put_map_image(token, mapID, image);
70 if (success) {
71 navigate(0);
72 } else {
73 alert("Error. Check logs.")
74 }
75 }
65 } 76 }
66 }; 77 };
67 78
68 const _edit_map_summary_route = async () => { 79 const _edit_map_summary_route = async () => {
69 if (window.confirm("Are you sure you want to submit this to the database?")) { 80 if (window.confirm("Are you sure you want to submit this to the database?")) {
70 await API.put_map_summary(mapID, routeContent); 81 if (token) {
82 routeContent.date += "T00:00:00Z";
83 const success = await API.put_map_summary(token, mapID, routeContent);
84 if (success) {
85 navigate(0);
86 } else {
87 alert("Error. Check logs.")
88 }
89 }
71 } 90 }
72 }; 91 };
73 92
74 const _create_map_summary_route = async () => { 93 const _create_map_summary_route = async () => {
75 if (window.confirm("Are you sure you want to submit this to the database?")) { 94 if (window.confirm("Are you sure you want to submit this to the database?")) {
76 await API.post_map_summary(mapID, routeContent); 95 if (token) {
96 routeContent.date += "T00:00:00Z";
97 const success = await API.post_map_summary(token, mapID, routeContent);
98 if (success) {
99 navigate(0);
100 } else {
101 alert("Error. Check logs.")
102 }
103 }
77 } 104 }
78 }; 105 };
79 106
80 const _delete_map_summary_route = async () => { 107 const _delete_map_summary_route = async () => {
81 if (window.confirm(`Are you sure you want to delete this run from the database? 108 if (window.confirm(`Are you sure you want to delete this run from the database?
82 ${data.summary.routes[selectedRun].category.name} ${data.summary.routes[selectedRun].history.score_count} portals ${data.summary.routes[selectedRun].history.runner_name}`)) { 109 ${data.summary.routes[selectedRun].category.name} ${data.summary.routes[selectedRun].history.score_count} portals ${data.summary.routes[selectedRun].history.runner_name}`)) {
83 await API.delete_map_summary(mapID, data.summary.routes[selectedRun].route_id); 110 if (token) {
111 const success = await API.delete_map_summary(token, mapID, data.summary.routes[selectedRun].route_id);
112 if (success) {
113 navigate(0);
114 } else {
115 alert("Error. Check logs.")
116 }
117 }
84 } 118 }
85 }; 119 };
86 120