diff options
Diffstat (limited to 'frontend/src/pages')
| -rw-r--r-- | frontend/src/pages/Profile.tsx | 19 |
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 @@ | |||
| 1 | import React from 'react'; | 1 | import React from 'react'; |
| 2 | import { Link, useLocation, useNavigate } from 'react-router-dom'; | 2 | import { Link, useLocation, useNavigate } from 'react-router-dom'; |
| 3 | 3 | ||
| 4 | import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon } from '../images/Images'; | 4 | import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon, DeleteIcon } from '../images/Images'; |
| 5 | import { UserProfile } from '../types/Profile'; | 5 | import { UserProfile } from '../types/Profile'; |
| 6 | import { Game, GameChapters } from '../types/Game'; | 6 | import { Game, GameChapters } from '../types/Game'; |
| 7 | import { Map } from '../types/Map'; | 7 | 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 | 12 | ||
| 12 | interface ProfileProps { | 13 | interface 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 | ||
| 18 | const Profile: React.FC<ProfileProps> = ({ profile, token, gameData }) => { | 20 | const 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" || |