From 53337bad0623a5f32c87d760bc03efb3cfe4eab6 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:06:15 +0300 Subject: feat/frontend: remove map select from upload run dialog (#239) --- frontend/src/api/Api.ts | 2 +- frontend/src/api/Maps.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'frontend/src/api') diff --git a/frontend/src/api/Api.ts b/frontend/src/api/Api.ts index 2e55ab4..4a3f907 100644 --- a/frontend/src/api/Api.ts +++ b/frontend/src/api/Api.ts @@ -35,7 +35,7 @@ export const API = { post_map_discussion: (token: string, map_id: string, content: MapDiscussionContent) => post_map_discussion(token, map_id, content), post_map_discussion_comment: (token: string, map_id: string, discussion_id: number, comment: string) => post_map_discussion_comment(token, map_id, discussion_id, comment), - post_record: (token: string, run: UploadRunContent) => post_record(token, run), + post_record: (token: string, run: UploadRunContent, map_id: number) => post_record(token, run, map_id), delete_map_discussion: (token: string, map_id: string, discussion_id: number) => delete_map_discussion(token, map_id, discussion_id), diff --git a/frontend/src/api/Maps.ts b/frontend/src/api/Maps.ts index 89657b5..3832a2e 100644 --- a/frontend/src/api/Maps.ts +++ b/frontend/src/api/Maps.ts @@ -73,9 +73,9 @@ export const delete_map_discussion = async (token: string, map_id: string, discu return response.data.success; }; -export const post_record = async (token: string, run: UploadRunContent): Promise<[boolean, string]> => { +export const post_record = async (token: string, run: UploadRunContent, map_id: number): Promise<[boolean, string]> => { if (run.partner_demo) { - const response = await axios.postForm(url(`maps/${run.map_id}/record`), { + const response = await axios.postForm(url(`maps/${map_id}/record`), { "host_demo": run.host_demo, "partner_demo": run.partner_demo, }, { @@ -83,16 +83,16 @@ export const post_record = async (token: string, run: UploadRunContent): Promise "Authorization": token, } }); - return [ response.data.success, response.data.message ]; + return [response.data.success, response.data.message]; } else { - const response = await axios.postForm(url(`maps/${run.map_id}/record`), { + const response = await axios.postForm(url(`maps/${map_id}/record`), { "host_demo": run.host_demo, }, { headers: { "Authorization": token, } }); - return [ response.data.success, response.data.message ]; + return [response.data.success, response.data.message]; } } -- cgit v1.2.3 From 9c3e5686f36bc4ba76d510f27adc89f378a3a658 Mon Sep 17 00:00:00 2001 From: Wolfboy248 <121288977+Wolfboy248@users.noreply.github.com> Date: Tue, 10 Dec 2024 07:16:37 +0100 Subject: fix/frontend: map pagination fix (#246) --- frontend/src/api/Api.ts | 2 +- frontend/src/api/Maps.ts | 4 ++-- frontend/src/components/Leaderboards.tsx | 21 +++++++++++++++++---- frontend/src/pages/Maps.tsx | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'frontend/src/api') diff --git a/frontend/src/api/Api.ts b/frontend/src/api/Api.ts index 4a3f907..862e688 100644 --- a/frontend/src/api/Api.ts +++ b/frontend/src/api/Api.ts @@ -29,7 +29,7 @@ export const API = { get_unofficial_rankings: () => get_unofficial_rankings(), // Maps get_map_summary: (map_id: string) => get_map_summary(map_id), - get_map_leaderboard: (map_id: string) => get_map_leaderboard(map_id), + get_map_leaderboard: (map_id: string, page: string) => get_map_leaderboard(map_id, page), get_map_discussions: (map_id: string) => get_map_discussions(map_id), get_map_discussion: (map_id: string, discussion_id: number) => get_map_discussion(map_id, discussion_id), diff --git a/frontend/src/api/Maps.ts b/frontend/src/api/Maps.ts index 3832a2e..aa967ce 100644 --- a/frontend/src/api/Maps.ts +++ b/frontend/src/api/Maps.ts @@ -8,8 +8,8 @@ export const get_map_summary = async (map_id: string): Promise => { return response.data.data; }; -export const get_map_leaderboard = async (map_id: string): Promise => { - const response = await axios.get(url(`maps/${map_id}/leaderboards`)); +export const get_map_leaderboard = async (map_id: string, page: string): Promise => { + const response = await axios.get(url(`maps/${map_id}/leaderboards?page=${page}`)); if (!response.data.success) { return undefined; } diff --git a/frontend/src/components/Leaderboards.tsx b/frontend/src/components/Leaderboards.tsx index 4a8b463..fb614fa 100644 --- a/frontend/src/components/Leaderboards.tsx +++ b/frontend/src/components/Leaderboards.tsx @@ -1,20 +1,33 @@ import React from 'react'; -import { Link } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; import { DownloadIcon, ThreedotIcon } from '@images/Images'; import { MapLeaderboard } from '@customTypes/Map'; import { ticks_to_time, time_ago } from '@utils/Time'; +import { API } from "@api/Api"; import useMessage from "@hooks/UseMessage"; import "@css/Maps.css" interface LeaderboardsProps { - data?: MapLeaderboard; + mapID: string; } -const Leaderboards: React.FC = ({ data }) => { +const Leaderboards: React.FC = ({ mapID }) => { + const navigate = useNavigate(); + const [data, setData] = React.useState(undefined); + const [pageNumber, setPageNumber] = React.useState(1); + + const _fetch_map_leaderboards = async () => { + const mapLeaderboards = await API.get_map_leaderboard(mapID, pageNumber.toString()); + setData(mapLeaderboards); + }; const { message, MessageDialogComponent } = useMessage(); - const [pageNumber, setPageNumber] = React.useState(1); + + React.useEffect(() => { + _fetch_map_leaderboards(); + console.log(data); + }, [pageNumber, navigate]) if (!data) { return ( diff --git a/frontend/src/pages/Maps.tsx b/frontend/src/pages/Maps.tsx index f1daa36..f73e8d2 100644 --- a/frontend/src/pages/Maps.tsx +++ b/frontend/src/pages/Maps.tsx @@ -35,7 +35,7 @@ const Maps: React.FC = ({ token, isModerator }) => { }; const _fetch_map_leaderboards = async () => { - const mapLeaderboards = await API.get_map_leaderboard(mapID); + const mapLeaderboards = await API.get_map_leaderboard(mapID, "1"); setMapLeaderboardData(mapLeaderboards); }; @@ -94,7 +94,7 @@ const Maps: React.FC = ({ token, isModerator }) => { {navState === 0 && } - {navState === 1 && } + {navState === 1 && } {navState === 2 && _fetch_map_discussions()} />} -- cgit v1.2.3