diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-31 23:58:14 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-31 23:58:14 +0300 |
| commit | f5ad360d02303ce27a65e67feb8ae38f1e26742c (patch) | |
| tree | b3e5b0fde361223275b8cc91fe0ccbdbb945ed13 /frontend/src/components | |
| parent | backend: remove auth check for viewing user page (diff) | |
| download | lphub-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')
| -rw-r--r-- | frontend/src/components/Discussions.tsx | 12 | ||||
| -rw-r--r-- | frontend/src/components/Leaderboards.tsx | 4 | ||||
| -rw-r--r-- | frontend/src/components/ModMenu.tsx | 16 |
3 files changed, 20 insertions, 12 deletions
diff --git a/frontend/src/components/Discussions.tsx b/frontend/src/components/Discussions.tsx index c22de79..0522910 100644 --- a/frontend/src/components/Discussions.tsx +++ b/frontend/src/components/Discussions.tsx | |||
| @@ -6,6 +6,7 @@ import { time_ago } from '../utils/Time'; | |||
| 6 | import { API } from '../api/Api'; | 6 | import { API } from '../api/Api'; |
| 7 | import "../css/Maps.css" | 7 | import "../css/Maps.css" |
| 8 | import { Link } from 'react-router-dom'; | 8 | import { Link } from 'react-router-dom'; |
| 9 | import useConfirm from '../hooks/UseConfirm'; | ||
| 9 | 10 | ||
| 10 | interface DiscussionsProps { | 11 | interface DiscussionsProps { |
| 11 | token?: string | 12 | token?: string |
| @@ -17,6 +18,8 @@ interface DiscussionsProps { | |||
| 17 | 18 | ||
| 18 | const Discussions: React.FC<DiscussionsProps> = ({ token, data, isModerator, mapID, onRefresh }) => { | 19 | const Discussions: React.FC<DiscussionsProps> = ({ token, data, isModerator, mapID, onRefresh }) => { |
| 19 | 20 | ||
| 21 | const { confirm, ConfirmDialogComponent } = useConfirm(); | ||
| 22 | |||
| 20 | const [discussionThread, setDiscussionThread] = React.useState<MapDiscussion | undefined>(undefined); | 23 | const [discussionThread, setDiscussionThread] = React.useState<MapDiscussion | undefined>(undefined); |
| 21 | const [discussionSearch, setDiscussionSearch] = React.useState<string>(""); | 24 | const [discussionSearch, setDiscussionSearch] = React.useState<string>(""); |
| 22 | 25 | ||
| @@ -48,7 +51,7 @@ const Discussions: React.FC<DiscussionsProps> = ({ token, data, isModerator, map | |||
| 48 | }; | 51 | }; |
| 49 | 52 | ||
| 50 | const _delete_map_discussion = async (discussion: MapDiscussionsDetail) => { | 53 | const _delete_map_discussion = async (discussion: MapDiscussionsDetail) => { |
| 51 | if (window.confirm(`Are you sure you want to remove post: ${discussion.title}?`)) { | 54 | if (await confirm("Delete Map Discussion", `Are you sure you want to remove post: ${discussion.title}?`)) { |
| 52 | if (token) { | 55 | if (token) { |
| 53 | await API.delete_map_discussion(token, mapID, discussion.id); | 56 | await API.delete_map_discussion(token, mapID, discussion.id); |
| 54 | onRefresh(); | 57 | onRefresh(); |
| @@ -58,6 +61,7 @@ const Discussions: React.FC<DiscussionsProps> = ({ token, data, isModerator, map | |||
| 58 | 61 | ||
| 59 | return ( | 62 | return ( |
| 60 | <section id='section7' className='summary3'> | 63 | <section id='section7' className='summary3'> |
| 64 | {ConfirmDialogComponent} | ||
| 61 | <div id='discussion-search'> | 65 | <div id='discussion-search'> |
| 62 | <input type="text" value={discussionSearch} placeholder={"Search for posts..."} onChange={(e) => setDiscussionSearch(e.target.value)} /> | 66 | <input type="text" value={discussionSearch} placeholder={"Search for posts..."} onChange={(e) => setDiscussionSearch(e.target.value)} /> |
| 63 | <div><button onClick={() => setCreateDiscussion(true)}>New Post</button></div> | 67 | <div><button onClick={() => setCreateDiscussion(true)}>New Post</button></div> |
| @@ -119,9 +123,9 @@ const Discussions: React.FC<DiscussionsProps> = ({ token, data, isModerator, map | |||
| 119 | } | 123 | } |
| 120 | </div> | 124 | </div> |
| 121 | <div id='discussion-send'> | 125 | <div id='discussion-send'> |
| 122 | <input type="text" value={createDiscussionCommentContent} placeholder={"Message"} | 126 | <input type="text" value={createDiscussionCommentContent} placeholder={"Message"} |
| 123 | onKeyDown={(e) => e.key === "Enter" && _create_map_discussion_comment(discussionThread.discussion.id)} | 127 | onKeyDown={(e) => e.key === "Enter" && _create_map_discussion_comment(discussionThread.discussion.id)} |
| 124 | onChange={(e) => setCreateDiscussionCommentContent(e.target.value)} /> | 128 | onChange={(e) => setCreateDiscussionCommentContent(e.target.value)} /> |
| 125 | <div><button onClick={() => { | 129 | <div><button onClick={() => { |
| 126 | if (createDiscussionCommentContent !== "") { | 130 | if (createDiscussionCommentContent !== "") { |
| 127 | _create_map_discussion_comment(discussionThread.discussion.id); | 131 | _create_map_discussion_comment(discussionThread.discussion.id); |
diff --git a/frontend/src/components/Leaderboards.tsx b/frontend/src/components/Leaderboards.tsx index 4a107ad..aaaee62 100644 --- a/frontend/src/components/Leaderboards.tsx +++ b/frontend/src/components/Leaderboards.tsx | |||
| @@ -91,14 +91,14 @@ const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { | |||
| 91 | 91 | ||
| 92 | {r.kind === "multiplayer" ? ( | 92 | {r.kind === "multiplayer" ? ( |
| 93 | <span> | 93 | <span> |
| 94 | <button onClick={() => { window.alert(`Host Demo ID: ${r.host_demo_id} \nParnter Demo ID: ${r.partner_demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> | 94 | <button onClick={() => { message("Demo Information", `Host Demo ID: ${r.host_demo_id} \nParnter Demo ID: ${r.partner_demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> |
| 95 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.partner_demo_id}`}><img src={DownloadIcon} alt="download" style={{ filter: "hue-rotate(160deg) contrast(60%) saturate(1000%)" }} /></button> | 95 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.partner_demo_id}`}><img src={DownloadIcon} alt="download" style={{ filter: "hue-rotate(160deg) contrast(60%) saturate(1000%)" }} /></button> |
| 96 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.host_demo_id}`}><img src={DownloadIcon} alt="download" style={{ filter: "hue-rotate(300deg) contrast(60%) saturate(1000%)" }} /></button> | 96 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.host_demo_id}`}><img src={DownloadIcon} alt="download" style={{ filter: "hue-rotate(300deg) contrast(60%) saturate(1000%)" }} /></button> |
| 97 | </span> | 97 | </span> |
| 98 | ) : r.kind === "singleplayer" && ( | 98 | ) : r.kind === "singleplayer" && ( |
| 99 | 99 | ||
| 100 | <span> | 100 | <span> |
| 101 | <button onClick={() => { message("Demo information", `Demo ID: ${r.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> | 101 | <button onClick={() => { message("Demo Information", `Demo ID: ${r.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> |
| 102 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.demo_id}`}><img src={DownloadIcon} alt="download" /></button> | 102 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.demo_id}`}><img src={DownloadIcon} alt="download" /></button> |
| 103 | </span> | 103 | </span> |
| 104 | )} | 104 | )} |
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> |