aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/pages/Profile.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/pages/Profile.tsx')
-rw-r--r--frontend/src/pages/Profile.tsx19
1 files changed, 16 insertions, 3 deletions
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 @@
1import React from 'react'; 1import React from 'react';
2import { Link, useLocation, useNavigate } from 'react-router-dom'; 2import { Link, useLocation, useNavigate } from 'react-router-dom';
3 3
4import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon } from '../images/Images'; 4import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon, DeleteIcon } from '../images/Images';
5import { UserProfile } from '../types/Profile'; 5import { UserProfile } from '../types/Profile';
6import { Game, GameChapters } from '../types/Game'; 6import { Game, GameChapters } from '../types/Game';
7import { Map } from '../types/Map'; 7import { Map } from '../types/Map';
8import { ticks_to_time } from '../utils/Time'; 8import { ticks_to_time } from '../utils/Time';
9import "../css/Profile.css"; 9import "../css/Profile.css";
10import { API } from '../api/Api'; 10import { API } from '../api/Api';
11import MapDeleteConfirmDialog from '../components/MapDeleteConfirmDialog';
11 12
12interface ProfileProps { 13interface ProfileProps {
13 profile?: UserProfile; 14 profile?: UserProfile;
14 token?: string; 15 token?: string;
15 gameData: Game[]; 16 gameData: Game[];
17 onDeleteRecord: () => void;
16} 18}
17 19
18const Profile: React.FC<ProfileProps> = ({ profile, token, gameData }) => { 20const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRecord }) => {
19 21
20 const [navState, setNavState] = React.useState(0); 22 const [navState, setNavState] = React.useState(0);
21 const [pageNumber, setPageNumber] = React.useState(1); 23 const [pageNumber, setPageNumber] = React.useState(1);
@@ -58,6 +60,16 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData }) => {
58 } 60 }
59 }; 61 };
60 62
63 const _delete_submission = async (map_id: number, record_id: number) => {
64 onDeleteRecord();
65 const api_success = await API.delete_map_record(token!, map_id, record_id);
66 if (api_success) {
67 window.alert("Successfully deleted record");
68 } else {
69 window.alert("Error: Could not delete record");
70 }
71 };
72
61 React.useEffect(() => { 73 React.useEffect(() => {
62 if (!profile) { 74 if (!profile) {
63 navigate("/"); 75 navigate("/");
@@ -228,7 +240,8 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData }) => {
228 <span>{e.date.split("T")[0]}</span> 240 <span>{e.date.split("T")[0]}</span>
229 <span style={{ flexDirection: "row-reverse" }}> 241 <span style={{ flexDirection: "row-reverse" }}>
230 242
231 <button onClick={() => { window.alert(`Demo ID: ${e.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> 243 <button style={{marginRight: "10px"}} onClick={() => { window.alert(`Demo ID: ${e.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button>
244 <button onClick={() => { _delete_submission(r.map_id, e.record_id) }}><img src={DeleteIcon}></img></button>
232 <button onClick={() => window.location.href = `/api/v1/demos?uuid=${e.demo_id}`}><img src={DownloadIcon} alt="download" /></button> 245 <button onClick={() => window.location.href = `/api/v1/demos?uuid=${e.demo_id}`}><img src={DownloadIcon} alt="download" /></button>
233 {i === 0 && r.scores.length > 1 ? <button onClick={() => { 246 {i === 0 && r.scores.length > 1 ? <button onClick={() => {
234 (document.querySelectorAll(".profileboard-record")[index % 20] as HTMLInputElement).style.height === "44px" || 247 (document.querySelectorAll(".profileboard-record")[index % 20] as HTMLInputElement).style.height === "44px" ||