diff options
| author | Wolfboy248 <121288977+Wolfboy248@users.noreply.github.com> | 2024-12-10 07:16:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 09:16:37 +0300 |
| commit | 9c3e5686f36bc4ba76d510f27adc89f378a3a658 (patch) | |
| tree | c55033ed5e4f153e027767be160fbcf94364f755 /frontend/src | |
| parent | docs/lphub: seperate contributors into a new file (#244) (diff) | |
| download | lphub-9c3e5686f36bc4ba76d510f27adc89f378a3a658.tar.gz lphub-9c3e5686f36bc4ba76d510f27adc89f378a3a658.tar.bz2 lphub-9c3e5686f36bc4ba76d510f27adc89f378a3a658.zip | |
fix/frontend: map pagination fix (#246)
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/api/Api.ts | 2 | ||||
| -rw-r--r-- | frontend/src/api/Maps.ts | 4 | ||||
| -rw-r--r-- | frontend/src/components/Leaderboards.tsx | 21 | ||||
| -rw-r--r-- | frontend/src/pages/Maps.tsx | 4 |
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 | ||
| 11 | export const get_map_leaderboard = async (map_id: string): Promise<MapLeaderboard | undefined> => { | 11 | export 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 @@ | |||
| 1 | import React from 'react'; | 1 | import React from 'react'; |
| 2 | import { Link } from 'react-router-dom'; | 2 | import { Link, useNavigate } from 'react-router-dom'; |
| 3 | 3 | ||
| 4 | import { DownloadIcon, ThreedotIcon } from '@images/Images'; | 4 | import { DownloadIcon, ThreedotIcon } from '@images/Images'; |
| 5 | import { MapLeaderboard } from '@customTypes/Map'; | 5 | import { MapLeaderboard } from '@customTypes/Map'; |
| 6 | import { ticks_to_time, time_ago } from '@utils/Time'; | 6 | import { ticks_to_time, time_ago } from '@utils/Time'; |
| 7 | import { API } from "@api/Api"; | ||
| 7 | import useMessage from "@hooks/UseMessage"; | 8 | import useMessage from "@hooks/UseMessage"; |
| 8 | import "@css/Maps.css" | 9 | import "@css/Maps.css" |
| 9 | 10 | ||
| 10 | interface LeaderboardsProps { | 11 | interface LeaderboardsProps { |
| 11 | data?: MapLeaderboard; | 12 | mapID: string; |
| 12 | } | 13 | } |
| 13 | 14 | ||
| 14 | const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { | 15 | const 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 | </> |