diff options
Diffstat (limited to 'frontend/src/api/Maps.ts')
| -rw-r--r-- | frontend/src/api/Maps.ts | 160 |
1 files changed, 110 insertions, 50 deletions
diff --git a/frontend/src/api/Maps.ts b/frontend/src/api/Maps.ts index aa967ce..3a22f88 100644 --- a/frontend/src/api/Maps.ts +++ b/frontend/src/api/Maps.ts | |||
| @@ -1,15 +1,25 @@ | |||
| 1 | import axios from "axios"; | 1 | import axios from 'axios'; |
| 2 | import { url } from "@api/Api"; | 2 | import { url } from '@api/Api'; |
| 3 | import { MapDiscussionContent, UploadRunContent } from "@customTypes/Content"; | 3 | import { MapDiscussionContent, UploadRunContent } from '@customTypes/Content'; |
| 4 | import { MapSummary, MapLeaderboard, MapDiscussions, MapDiscussion } from "@customTypes/Map"; | 4 | import { |
| 5 | MapSummary, | ||
| 6 | MapLeaderboard, | ||
| 7 | MapDiscussions, | ||
| 8 | MapDiscussion, | ||
| 9 | } from '@customTypes/Map'; | ||
| 5 | 10 | ||
| 6 | export const get_map_summary = async (map_id: string): Promise<MapSummary> => { | 11 | export const get_map_summary = async (map_id: string): Promise<MapSummary> => { |
| 7 | const response = await axios.get(url(`maps/${map_id}/summary`)) | 12 | const response = await axios.get(url(`maps/${map_id}/summary`)); |
| 8 | return response.data.data; | 13 | return response.data.data; |
| 9 | }; | 14 | }; |
| 10 | 15 | ||
| 11 | export const get_map_leaderboard = async (map_id: string, page: string): Promise<MapLeaderboard | undefined> => { | 16 | export const get_map_leaderboard = async ( |
| 12 | const response = await axios.get(url(`maps/${map_id}/leaderboards?page=${page}`)); | 17 | map_id: string, |
| 18 | page: string | ||
| 19 | ): Promise<MapLeaderboard | undefined> => { | ||
| 20 | const response = await axios.get( | ||
| 21 | url(`maps/${map_id}/leaderboards?page=${page}`) | ||
| 22 | ); | ||
| 13 | if (!response.data.success) { | 23 | if (!response.data.success) { |
| 14 | return undefined; | 24 | return undefined; |
| 15 | } | 25 | } |
| @@ -25,7 +35,9 @@ export const get_map_leaderboard = async (map_id: string, page: string): Promise | |||
| 25 | return data; | 35 | return data; |
| 26 | }; | 36 | }; |
| 27 | 37 | ||
| 28 | export const get_map_discussions = async (map_id: string): Promise<MapDiscussions | undefined> => { | 38 | export const get_map_discussions = async ( |
| 39 | map_id: string | ||
| 40 | ): Promise<MapDiscussions | undefined> => { | ||
| 29 | const response = await axios.get(url(`maps/${map_id}/discussions`)); | 41 | const response = await axios.get(url(`maps/${map_id}/discussions`)); |
| 30 | if (!response.data.data.discussions) { | 42 | if (!response.data.data.discussions) { |
| 31 | return undefined; | 43 | return undefined; |
| @@ -33,74 +45,122 @@ export const get_map_discussions = async (map_id: string): Promise<MapDiscussion | |||
| 33 | return response.data.data; | 45 | return response.data.data; |
| 34 | }; | 46 | }; |
| 35 | 47 | ||
| 36 | export const get_map_discussion = async (map_id: string, discussion_id: number): Promise<MapDiscussion | undefined> => { | 48 | export const get_map_discussion = async ( |
| 37 | const response = await axios.get(url(`maps/${map_id}/discussions/${discussion_id}`)); | 49 | map_id: string, |
| 50 | discussion_id: number | ||
| 51 | ): Promise<MapDiscussion | undefined> => { | ||
| 52 | const response = await axios.get( | ||
| 53 | url(`maps/${map_id}/discussions/${discussion_id}`) | ||
| 54 | ); | ||
| 38 | if (!response.data.data.discussion) { | 55 | if (!response.data.data.discussion) { |
| 39 | return undefined; | 56 | return undefined; |
| 40 | } | 57 | } |
| 41 | return response.data.data; | 58 | return response.data.data; |
| 42 | }; | 59 | }; |
| 43 | 60 | ||
| 44 | export const post_map_discussion = async (token: string, map_id: string, content: MapDiscussionContent): Promise<boolean> => { | 61 | export const post_map_discussion = async ( |
| 45 | const response = await axios.post(url(`maps/${map_id}/discussions`), { | 62 | token: string, |
| 46 | "title": content.title, | 63 | map_id: string, |
| 47 | "content": content.content, | 64 | content: MapDiscussionContent |
| 48 | }, { | 65 | ): Promise<boolean> => { |
| 49 | headers: { | 66 | const response = await axios.post( |
| 50 | "Authorization": token, | 67 | url(`maps/${map_id}/discussions`), |
| 68 | { | ||
| 69 | title: content.title, | ||
| 70 | content: content.content, | ||
| 71 | }, | ||
| 72 | { | ||
| 73 | headers: { | ||
| 74 | Authorization: token, | ||
| 75 | }, | ||
| 51 | } | 76 | } |
| 52 | }); | 77 | ); |
| 53 | return response.data.success; | 78 | return response.data.success; |
| 54 | }; | 79 | }; |
| 55 | 80 | ||
| 56 | export const post_map_discussion_comment = async (token: string, map_id: string, discussion_id: number, comment: string): Promise<boolean> => { | 81 | export const post_map_discussion_comment = async ( |
| 57 | const response = await axios.post(url(`maps/${map_id}/discussions/${discussion_id}`), { | 82 | token: string, |
| 58 | "comment": comment, | 83 | map_id: string, |
| 59 | }, { | 84 | discussion_id: number, |
| 60 | headers: { | 85 | comment: string |
| 61 | "Authorization": token, | 86 | ): Promise<boolean> => { |
| 87 | const response = await axios.post( | ||
| 88 | url(`maps/${map_id}/discussions/${discussion_id}`), | ||
| 89 | { | ||
| 90 | comment: comment, | ||
| 91 | }, | ||
| 92 | { | ||
| 93 | headers: { | ||
| 94 | Authorization: token, | ||
| 95 | }, | ||
| 62 | } | 96 | } |
| 63 | }); | 97 | ); |
| 64 | return response.data.success; | 98 | return response.data.success; |
| 65 | }; | 99 | }; |
| 66 | 100 | ||
| 67 | export const delete_map_discussion = async (token: string, map_id: string, discussion_id: number): Promise<boolean> => { | 101 | export const delete_map_discussion = async ( |
| 68 | const response = await axios.delete(url(`maps/${map_id}/discussions/${discussion_id}`), { | 102 | token: string, |
| 69 | headers: { | 103 | map_id: string, |
| 70 | "Authorization": token, | 104 | discussion_id: number |
| 105 | ): Promise<boolean> => { | ||
| 106 | const response = await axios.delete( | ||
| 107 | url(`maps/${map_id}/discussions/${discussion_id}`), | ||
| 108 | { | ||
| 109 | headers: { | ||
| 110 | Authorization: token, | ||
| 111 | }, | ||
| 71 | } | 112 | } |
| 72 | }); | 113 | ); |
| 73 | return response.data.success; | 114 | return response.data.success; |
| 74 | }; | 115 | }; |
| 75 | 116 | ||
| 76 | export const post_record = async (token: string, run: UploadRunContent, map_id: number): Promise<[boolean, string]> => { | 117 | export const post_record = async ( |
| 118 | token: string, | ||
| 119 | run: UploadRunContent, | ||
| 120 | map_id: number | ||
| 121 | ): Promise<[boolean, string]> => { | ||
| 77 | if (run.partner_demo) { | 122 | if (run.partner_demo) { |
| 78 | const response = await axios.postForm(url(`maps/${map_id}/record`), { | 123 | const response = await axios.postForm( |
| 79 | "host_demo": run.host_demo, | 124 | url(`maps/${map_id}/record`), |
| 80 | "partner_demo": run.partner_demo, | 125 | { |
| 81 | }, { | 126 | host_demo: run.host_demo, |
| 82 | headers: { | 127 | partner_demo: run.partner_demo, |
| 83 | "Authorization": token, | 128 | }, |
| 129 | { | ||
| 130 | headers: { | ||
| 131 | Authorization: token, | ||
| 132 | }, | ||
| 84 | } | 133 | } |
| 85 | }); | 134 | ); |
| 86 | return [response.data.success, response.data.message]; | 135 | return [response.data.success, response.data.message]; |
| 87 | } else { | 136 | } else { |
| 88 | const response = await axios.postForm(url(`maps/${map_id}/record`), { | 137 | const response = await axios.postForm( |
| 89 | "host_demo": run.host_demo, | 138 | url(`maps/${map_id}/record`), |
| 90 | }, { | 139 | { |
| 91 | headers: { | 140 | host_demo: run.host_demo, |
| 92 | "Authorization": token, | 141 | }, |
| 142 | { | ||
| 143 | headers: { | ||
| 144 | Authorization: token, | ||
| 145 | }, | ||
| 93 | } | 146 | } |
| 94 | }); | 147 | ); |
| 95 | return [response.data.success, response.data.message]; | 148 | return [response.data.success, response.data.message]; |
| 96 | } | 149 | } |
| 97 | } | 150 | }; |
| 98 | 151 | ||
| 99 | export const delete_map_record = async (token: string, map_id: number, record_id: number): Promise<boolean> => { | 152 | export const delete_map_record = async ( |
| 100 | const response = await axios.delete(url(`maps/${map_id}/record/${record_id}`), { | 153 | token: string, |
| 101 | headers: { | 154 | map_id: number, |
| 102 | "Authorization": token, | 155 | record_id: number |
| 156 | ): Promise<boolean> => { | ||
| 157 | const response = await axios.delete( | ||
| 158 | url(`maps/${map_id}/record/${record_id}`), | ||
| 159 | { | ||
| 160 | headers: { | ||
| 161 | Authorization: token, | ||
| 162 | }, | ||
| 103 | } | 163 | } |
| 104 | }); | 164 | ); |
| 105 | return response.data.success; | 165 | return response.data.success; |
| 106 | }; | 166 | }; |