aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/api/Api.ts2
-rw-r--r--frontend/src/api/Maps.ts4
-rw-r--r--frontend/src/components/Leaderboards.tsx21
-rw-r--r--frontend/src/pages/Maps.tsx4
4 files changed, 22 insertions, 9 deletions
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 = {
29 get_unofficial_rankings: () => get_unofficial_rankings(), 29 get_unofficial_rankings: () => get_unofficial_rankings(),
30 // Maps 30 // Maps
31 get_map_summary: (map_id: string) => get_map_summary(map_id), 31 get_map_summary: (map_id: string) => get_map_summary(map_id),
32 get_map_leaderboard: (map_id: string) => get_map_leaderboard(map_id), 32 get_map_leaderboard: (map_id: string, page: string) => get_map_leaderboard(map_id, page),
33 get_map_discussions: (map_id: string) => get_map_discussions(map_id), 33 get_map_discussions: (map_id: string) => get_map_discussions(map_id),
34 get_map_discussion: (map_id: string, discussion_id: number) => get_map_discussion(map_id, discussion_id), 34 get_map_discussion: (map_id: string, discussion_id: number) => get_map_discussion(map_id, discussion_id),
35 35
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<MapSummary> => {
8 return response.data.data; 8 return response.data.data;
9}; 9};
10 10
11export const get_map_leaderboard = async (map_id: string): Promise<MapLeaderboard | undefined> => { 11export const get_map_leaderboard = async (map_id: string, page: string): Promise<MapLeaderboard | undefined> => {
12 const response = await axios.get(url(`maps/${map_id}/leaderboards`)); 12 const response = await axios.get(url(`maps/${map_id}/leaderboards?page=${page}`));
13 if (!response.data.success) { 13 if (!response.data.success) {
14 return undefined; 14 return undefined;
15 } 15 }
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 @@
1import React from 'react'; 1import React from 'react';
2import { Link } from 'react-router-dom'; 2import { Link, useNavigate } from 'react-router-dom';
3 3
4import { DownloadIcon, ThreedotIcon } from '@images/Images'; 4import { DownloadIcon, ThreedotIcon } from '@images/Images';
5import { MapLeaderboard } from '@customTypes/Map'; 5import { MapLeaderboard } from '@customTypes/Map';
6import { ticks_to_time, time_ago } from '@utils/Time'; 6import { ticks_to_time, time_ago } from '@utils/Time';
7import { API } from "@api/Api";
7import useMessage from "@hooks/UseMessage"; 8import useMessage from "@hooks/UseMessage";
8import "@css/Maps.css" 9import "@css/Maps.css"
9 10
10interface LeaderboardsProps { 11interface LeaderboardsProps {
11 data?: MapLeaderboard; 12 mapID: string;
12} 13}
13 14
14const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { 15const Leaderboards: React.FC<LeaderboardsProps> = ({ mapID }) => {
16 const navigate = useNavigate();
17 const [data, setData] = React.useState<MapLeaderboard | undefined>(undefined);
18 const [pageNumber, setPageNumber] = React.useState<number>(1);
19
20 const _fetch_map_leaderboards = async () => {
21 const mapLeaderboards = await API.get_map_leaderboard(mapID, pageNumber.toString());
22 setData(mapLeaderboards);
23 };
15 24
16 const { message, MessageDialogComponent } = useMessage(); 25 const { message, MessageDialogComponent } = useMessage();
17 const [pageNumber, setPageNumber] = React.useState<number>(1); 26
27 React.useEffect(() => {
28 _fetch_map_leaderboards();
29 console.log(data);
30 }, [pageNumber, navigate])
18 31
19 if (!data) { 32 if (!data) {
20 return ( 33 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<MapProps> = ({ token, isModerator }) => {
35 }; 35 };
36 36
37 const _fetch_map_leaderboards = async () => { 37 const _fetch_map_leaderboards = async () => {
38 const mapLeaderboards = await API.get_map_leaderboard(mapID); 38 const mapLeaderboards = await API.get_map_leaderboard(mapID, "1");
39 setMapLeaderboardData(mapLeaderboards); 39 setMapLeaderboardData(mapLeaderboards);
40 }; 40 };
41 41
@@ -94,7 +94,7 @@ const Maps: React.FC<MapProps> = ({ token, isModerator }) => {
94 </section> 94 </section>
95 95
96 {navState === 0 && <Summary selectedRun={selectedRun} setSelectedRun={setSelectedRun} data={mapSummaryData} />} 96 {navState === 0 && <Summary selectedRun={selectedRun} setSelectedRun={setSelectedRun} data={mapSummaryData} />}
97 {navState === 1 && <Leaderboards data={mapLeaderboardData} />} 97 {navState === 1 && <Leaderboards mapID={mapID} />}
98 {navState === 2 && <Discussions data={mapDiscussionsData} token={token} isModerator={isModerator} mapID={mapID} onRefresh={() => _fetch_map_discussions()} />} 98 {navState === 2 && <Discussions data={mapDiscussionsData} token={token} isModerator={isModerator} mapID={mapID} onRefresh={() => _fetch_map_discussions()} />}
99 </main> 99 </main>
100 </> 100 </>