From d9974ede3b3914377beb4b07d78885c48bd74aac Mon Sep 17 00:00:00 2001 From: Wolfboy248 Date: Fri, 18 Oct 2024 17:01:01 +0200 Subject: refactor: delete run on profile --- frontend/src/pages/Profile.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'frontend/src/pages') diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index e20d930..5e39308 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx @@ -1,21 +1,23 @@ import React from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; -import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon } from '../images/Images'; +import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon, DeleteIcon } from '../images/Images'; import { UserProfile } from '../types/Profile'; import { Game, GameChapters } from '../types/Game'; import { Map } from '../types/Map'; import { ticks_to_time } from '../utils/Time'; import "../css/Profile.css"; import { API } from '../api/Api'; +import MapDeleteConfirmDialog from '../components/MapDeleteConfirmDialog'; interface ProfileProps { profile?: UserProfile; token?: string; gameData: Game[]; + onDeleteRecord: () => void; } -const Profile: React.FC = ({ profile, token, gameData }) => { +const Profile: React.FC = ({ profile, token, gameData, onDeleteRecord }) => { const [navState, setNavState] = React.useState(0); const [pageNumber, setPageNumber] = React.useState(1); @@ -58,6 +60,16 @@ const Profile: React.FC = ({ profile, token, gameData }) => { } }; + const _delete_submission = async (map_id: number, record_id: number) => { + onDeleteRecord(); + const api_success = await API.delete_map_record(token!, map_id, record_id); + if (api_success) { + window.alert("Successfully deleted record"); + } else { + window.alert("Error: Could not delete record"); + } + }; + React.useEffect(() => { if (!profile) { navigate("/"); @@ -228,7 +240,8 @@ const Profile: React.FC = ({ profile, token, gameData }) => { {e.date.split("T")[0]} - + + {i === 0 && r.scores.length > 1 ?