diff options
Diffstat (limited to 'frontend/src/api/Maps.tsx')
| -rw-r--r-- | frontend/src/api/Maps.tsx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/frontend/src/api/Maps.tsx b/frontend/src/api/Maps.tsx new file mode 100644 index 0000000..fbad78c --- /dev/null +++ b/frontend/src/api/Maps.tsx | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | import axios from "axios"; | ||
| 2 | import { url } from "./Api"; | ||
| 3 | import { MapDiscussionContent } from "../types/Content"; | ||
| 4 | import { MapSummary, MapLeaderboard, MapDiscussions, MapDiscussion } from "../types/Map"; | ||
| 5 | |||
| 6 | export const get_map_summary = async (map_id: string): Promise<MapSummary> => { | ||
| 7 | const response = await axios.get(url(`maps/${map_id}/summary`)) | ||
| 8 | return response.data.data; | ||
| 9 | }; | ||
| 10 | |||
| 11 | export const get_map_leaderboard = async (map_id: string): Promise<MapLeaderboard | undefined> => { | ||
| 12 | const response = await axios.get(url(`maps/${map_id}/leaderboards`)); | ||
| 13 | console.log(response) | ||
| 14 | if (!response.data.success) { | ||
| 15 | return undefined; | ||
| 16 | } | ||
| 17 | const data = response.data.data; | ||
| 18 | console.log(data.records) | ||
| 19 | // map the kind of leaderboard | ||
| 20 | data.records = data.records.map((record: any) => { | ||
| 21 | if (record.host && record.partner) { | ||
| 22 | return { ...record, kind: 'multiplayer' }; | ||
| 23 | } else { | ||
| 24 | return { ...record, kind: 'singleplayer' }; | ||
| 25 | } | ||
| 26 | }); | ||
| 27 | return data; | ||
| 28 | }; | ||
| 29 | |||
| 30 | export const get_map_discussions = async (map_id: string): Promise<MapDiscussions | undefined> => { | ||
| 31 | const response = await axios.get(url(`maps/${map_id}/discussions`)); | ||
| 32 | if (!response.data.data.discussions) { | ||
| 33 | return undefined; | ||
| 34 | } | ||
| 35 | return response.data.data; | ||
| 36 | }; | ||
| 37 | |||
| 38 | export const get_map_discussion = async (map_id: string, discussion_id: number): Promise<MapDiscussion | undefined> => { | ||
| 39 | const response = await axios.get(url(`maps/${map_id}/discussions/${discussion_id}`)); | ||
| 40 | if (!response.data.data.discussion) { | ||
| 41 | return undefined; | ||
| 42 | } | ||
| 43 | return response.data.data; | ||
| 44 | }; | ||
| 45 | |||
| 46 | export const post_map_discussion = async (token: string, map_id: string, content: MapDiscussionContent): Promise<boolean> => { | ||
| 47 | const response = await axios.post(url(`maps/${map_id}/discussions`), { | ||
| 48 | "title": content.title, | ||
| 49 | "content": content.content, | ||
| 50 | }, { | ||
| 51 | headers: { | ||
| 52 | "Authorization": token, | ||
| 53 | } | ||
| 54 | }); | ||
| 55 | return response.data.success; | ||
| 56 | }; | ||
| 57 | |||
| 58 | export const post_map_discussion_comment = async (token: string, map_id: string, discussion_id: number, comment: string): Promise<boolean> => { | ||
| 59 | const response = await axios.post(url(`maps/${map_id}/discussions/${discussion_id}`), { | ||
| 60 | "comment": comment, | ||
| 61 | }, { | ||
| 62 | headers: { | ||
| 63 | "Authorization": token, | ||
| 64 | } | ||
| 65 | }); | ||
| 66 | return response.data.success; | ||
| 67 | }; | ||
| 68 | |||
| 69 | export const delete_map_discussion = async (token: string, map_id: string, discussion_id: number): Promise<boolean> => { | ||
| 70 | const response = await axios.delete(url(`maps/${map_id}/discussions/${discussion_id}`), { | ||
| 71 | headers: { | ||
| 72 | "Authorization": token, | ||
| 73 | } | ||
| 74 | }); | ||
| 75 | return response.data.success; | ||
| 76 | }; | ||