diff options
| author | Wolfboy248 <105884620+Wolfboy248@users.noreply.github.com> | 2024-10-20 00:27:38 +0200 |
|---|---|---|
| committer | Wolfboy248 <105884620+Wolfboy248@users.noreply.github.com> | 2024-10-20 00:27:38 +0200 |
| commit | 8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95 (patch) | |
| tree | cf23b52befb9af6d16321b9e9031ace724543875 /frontend/src/pages | |
| parent | backend: actually fix download demo (diff) | |
| download | lphub-8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95.tar.gz lphub-8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95.tar.bz2 lphub-8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95.zip | |
refactor: custom modals
Diffstat (limited to 'frontend/src/pages')
| -rw-r--r-- | frontend/src/pages/Profile.tsx | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index 09033a5..bf79a65 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx | |||
| @@ -8,7 +8,8 @@ import { Map } from '../types/Map'; | |||
| 8 | import { ticks_to_time } from '../utils/Time'; | 8 | import { ticks_to_time } from '../utils/Time'; |
| 9 | import "../css/Profile.css"; | 9 | import "../css/Profile.css"; |
| 10 | import { API } from '../api/Api'; | 10 | import { API } from '../api/Api'; |
| 11 | import MapDeleteConfirmDialog from '../components/MapDeleteConfirmDialog'; | 11 | import useConfirm from '../components/UseConfirm'; |
| 12 | import useMessage from '../components/UseMessage'; | ||
| 12 | 13 | ||
| 13 | interface ProfileProps { | 14 | interface ProfileProps { |
| 14 | profile?: UserProfile; | 15 | profile?: UserProfile; |
| @@ -18,7 +19,8 @@ interface ProfileProps { | |||
| 18 | } | 19 | } |
| 19 | 20 | ||
| 20 | const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRecord }) => { | 21 | const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRecord }) => { |
| 21 | 22 | const { confirm, ConfirmDialogComponent } = useConfirm("Delete record?", "This action cannot be undone"); | |
| 23 | const { message, MessageDialogComponent } = useMessage(); | ||
| 22 | const [navState, setNavState] = React.useState(0); | 24 | const [navState, setNavState] = React.useState(0); |
| 23 | const [pageNumber, setPageNumber] = React.useState(1); | 25 | const [pageNumber, setPageNumber] = React.useState(1); |
| 24 | const [pageMax, setPageMax] = React.useState(0); | 26 | const [pageMax, setPageMax] = React.useState(0); |
| @@ -61,12 +63,17 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 61 | }; | 63 | }; |
| 62 | 64 | ||
| 63 | const _delete_submission = async (map_id: number, record_id: number) => { | 65 | const _delete_submission = async (map_id: number, record_id: number) => { |
| 64 | onDeleteRecord(); | 66 | const userConfirmed = await confirm(); |
| 67 | |||
| 68 | if (!userConfirmed) { | ||
| 69 | return; | ||
| 70 | } | ||
| 71 | |||
| 65 | 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); |
| 66 | if (api_success) { | 73 | if (api_success) { |
| 67 | window.alert("Successfully deleted record"); | 74 | message("Success", "Successfully deleted record"); |
| 68 | } else { | 75 | } else { |
| 69 | window.alert("Error: Could not delete record"); | 76 | message("Error", "Could not delete record"); |
| 70 | } | 77 | } |
| 71 | }; | 78 | }; |
| 72 | 79 | ||
| @@ -96,6 +103,8 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 96 | 103 | ||
| 97 | return ( | 104 | return ( |
| 98 | <main> | 105 | <main> |
| 106 | {ConfirmDialogComponent} | ||
| 107 | {MessageDialogComponent} | ||
| 99 | <section id='section1' className='profile'> | 108 | <section id='section1' className='profile'> |
| 100 | 109 | ||
| 101 | {profile.profile | 110 | {profile.profile |