diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-11-04 13:47:50 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-04 13:47:50 +0300 |
| commit | eae19bb1b047b3568e7a9a624b50e80886e56331 (patch) | |
| tree | aa3215377fd1a7714e4c5763f9abf9d7dc7def2b /frontend/src/api/Maps.ts | |
| parent | fix: remove insert trigger on users, check insert user on login err (#224) (diff) | |
| download | lphub-eae19bb1b047b3568e7a9a624b50e80886e56331.tar.gz lphub-eae19bb1b047b3568e7a9a624b50e80886e56331.tar.bz2 lphub-eae19bb1b047b3568e7a9a624b50e80886e56331.zip | |
feat/frontend: optimizing imports, file extensions (#230)
Co-authored-by: FifthWit <fifthwitbusiness@gmail.com>
Diffstat (limited to 'frontend/src/api/Maps.ts')
| -rw-r--r-- | frontend/src/api/Maps.ts | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/frontend/src/api/Maps.ts b/frontend/src/api/Maps.ts new file mode 100644 index 0000000..89657b5 --- /dev/null +++ b/frontend/src/api/Maps.ts | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | import axios from "axios"; | ||
| 2 | import { url } from "@api/Api"; | ||
| 3 | import { MapDiscussionContent, UploadRunContent } from "@customTypes/Content"; | ||
| 4 | import { MapSummary, MapLeaderboard, MapDiscussions, MapDiscussion } from "@customTypes/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 | if (!response.data.success) { | ||
| 14 | return undefined; | ||
| 15 | } | ||
| 16 | const data = response.data.data; | ||
| 17 | // map the kind of leaderboard | ||
| 18 | data.records = data.records.map((record: any) => { | ||
| 19 | if (record.host && record.partner) { | ||
| 20 | return { ...record, kind: 'multiplayer' }; | ||
| 21 | } else { | ||
| 22 | return { ...record, kind: 'singleplayer' }; | ||
| 23 | } | ||
| 24 | }); | ||
| 25 | return data; | ||
| 26 | }; | ||
| 27 | |||
| 28 | export const get_map_discussions = async (map_id: string): Promise<MapDiscussions | undefined> => { | ||
| 29 | const response = await axios.get(url(`maps/${map_id}/discussions`)); | ||
| 30 | if (!response.data.data.discussions) { | ||
| 31 | return undefined; | ||
| 32 | } | ||
| 33 | return response.data.data; | ||
| 34 | }; | ||
| 35 | |||
| 36 | export const get_map_discussion = async (map_id: string, discussion_id: number): Promise<MapDiscussion | undefined> => { | ||
| 37 | const response = await axios.get(url(`maps/${map_id}/discussions/${discussion_id}`)); | ||
| 38 | if (!response.data.data.discussion) { | ||
| 39 | return undefined; | ||
| 40 | } | ||
| 41 | return response.data.data; | ||
| 42 | }; | ||
| 43 | |||
| 44 | export const post_map_discussion = async (token: string, map_id: string, content: MapDiscussionContent): Promise<boolean> => { | ||
| 45 | const response = await axios.post(url(`maps/${map_id}/discussions`), { | ||
| 46 | "title": content.title, | ||
| 47 | "content": content.content, | ||
| 48 | }, { | ||
| 49 | headers: { | ||
| 50 | "Authorization": token, | ||
| 51 | } | ||
| 52 | }); | ||
| 53 | return response.data.success; | ||
| 54 | }; | ||
| 55 | |||
| 56 | export const post_map_discussion_comment = async (token: string, map_id: string, discussion_id: number, comment: string): Promise<boolean> => { | ||
| 57 | const response = await axios.post(url(`maps/${map_id}/discussions/${discussion_id}`), { | ||
| 58 | "comment": comment, | ||
| 59 | }, { | ||
| 60 | headers: { | ||
| 61 | "Authorization": token, | ||
| 62 | } | ||
| 63 | }); | ||
| 64 | return response.data.success; | ||
| 65 | }; | ||
| 66 | |||
| 67 | export const delete_map_discussion = async (token: string, map_id: string, discussion_id: number): Promise<boolean> => { | ||
| 68 | const response = await axios.delete(url(`maps/${map_id}/discussions/${discussion_id}`), { | ||
| 69 | headers: { | ||
| 70 | "Authorization": token, | ||
| 71 | } | ||
| 72 | }); | ||
| 73 | return response.data.success; | ||
| 74 | }; | ||
| 75 | |||
| 76 | export const post_record = async (token: string, run: UploadRunContent): Promise<[boolean, string]> => { | ||
| 77 | if (run.partner_demo) { | ||
| 78 | const response = await axios.postForm(url(`maps/${run.map_id}/record`), { | ||
| 79 | "host_demo": run.host_demo, | ||
| 80 | "partner_demo": run.partner_demo, | ||
| 81 | }, { | ||
| 82 | headers: { | ||
| 83 | "Authorization": token, | ||
| 84 | } | ||
| 85 | }); | ||
| 86 | return [ response.data.success, response.data.message ]; | ||
| 87 | } else { | ||
| 88 | const response = await axios.postForm(url(`maps/${run.map_id}/record`), { | ||
| 89 | "host_demo": run.host_demo, | ||
| 90 | }, { | ||
| 91 | headers: { | ||
| 92 | "Authorization": token, | ||
| 93 | } | ||
| 94 | }); | ||
| 95 | return [ response.data.success, response.data.message ]; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | export const delete_map_record = async (token: string, map_id: number, record_id: number): Promise<boolean> => { | ||
| 100 | const response = await axios.delete(url(`maps/${map_id}/record/${record_id}`), { | ||
| 101 | headers: { | ||
| 102 | "Authorization": token, | ||
| 103 | } | ||
| 104 | }); | ||
| 105 | return response.data.success; | ||
| 106 | }; | ||