From e40f07211f5f15dcb138e2520a76d13afd3c0cfd Mon Sep 17 00:00:00 2001 From: FifthWit Date: Thu, 30 Jan 2025 10:44:30 -0600 Subject: formatted with prettier --- frontend/src/api/Api.ts | 18 ++--- frontend/src/api/Auth.ts | 8 +-- frontend/src/api/Games.ts | 28 ++++---- frontend/src/api/Maps.ts | 160 +++++++++++++++++++++++++++++-------------- frontend/src/api/Mod.ts | 104 ++++++++++++++++++---------- frontend/src/api/Rankings.ts | 6 +- frontend/src/api/User.ts | 6 +- 7 files changed, 211 insertions(+), 119 deletions(-) (limited to 'frontend/src/api') diff --git a/frontend/src/api/Api.ts b/frontend/src/api/Api.ts index 0e1658c..b98dda3 100644 --- a/frontend/src/api/Api.ts +++ b/frontend/src/api/Api.ts @@ -1,14 +1,14 @@ -import { MapDiscussionContent, ModMenuContent } from "@customTypes/Content"; -import { delete_token, get_token } from "@api/Auth"; -import { get_user, get_profile, post_profile } from "@api/User"; +import { MapDiscussionContent, ModMenuContent } from '@customTypes/Content'; +import { delete_token, get_token } from '@api/Auth'; +import { get_user, get_profile, post_profile } from '@api/User'; import { get_games, get_chapters, get_games_chapters, get_game_maps, get_search, -} from "@api/Games"; -import { get_official_rankings, get_unofficial_rankings } from "@api/Rankings"; +} from '@api/Games'; +import { get_official_rankings, get_unofficial_rankings } from '@api/Rankings'; import { get_map_summary, get_map_leaderboard, @@ -19,14 +19,14 @@ import { delete_map_discussion, post_record, delete_map_record, -} from "@api/Maps"; +} from '@api/Maps'; import { delete_map_summary, post_map_summary, put_map_image, put_map_summary, -} from "@api/Mod"; -import { UploadRunContent } from "@customTypes/Content"; +} from '@api/Mod'; +import { UploadRunContent } from '@customTypes/Content'; // add new api call function entries here // example usage: API.get_games(); @@ -91,7 +91,7 @@ export const API = { delete_map_summary(token, map_id, route_id), }; -const BASE_API_URL: string = "/api/v1/"; +const BASE_API_URL: string = '/api/v1/'; export function url(path: string): string { return BASE_API_URL + path; diff --git a/frontend/src/api/Auth.ts b/frontend/src/api/Auth.ts index 875c7e5..e495d47 100644 --- a/frontend/src/api/Auth.ts +++ b/frontend/src/api/Auth.ts @@ -1,8 +1,8 @@ -import axios from "axios"; -import { url } from "@api/Api"; +import axios from 'axios'; +import { url } from '@api/Api'; export const get_token = async (): Promise => { - const response = await axios.get(url(`token`)) + const response = await axios.get(url(`token`)); if (!response.data.success) { return undefined; } @@ -10,5 +10,5 @@ export const get_token = async (): Promise => { }; export const delete_token = async () => { - await axios.delete(url("token")); + await axios.delete(url('token')); }; diff --git a/frontend/src/api/Games.ts b/frontend/src/api/Games.ts index 72bb4b3..0e47091 100644 --- a/frontend/src/api/Games.ts +++ b/frontend/src/api/Games.ts @@ -1,31 +1,35 @@ -import axios from "axios"; -import { url } from "@api/Api"; -import { GameChapter, GamesChapters } from "@customTypes/Chapters"; -import { Game } from "@customTypes/Game"; -import { Map } from "@customTypes/Map"; -import { Search } from "@customTypes/Search"; +import axios from 'axios'; +import { url } from '@api/Api'; +import { GameChapter, GamesChapters } from '@customTypes/Chapters'; +import { Game } from '@customTypes/Game'; +import { Map } from '@customTypes/Map'; +import { Search } from '@customTypes/Search'; export const get_games = async (): Promise => { - const response = await axios.get(url(`games`)) + const response = await axios.get(url(`games`)); return response.data.data; }; -export const get_chapters = async (chapter_id: string): Promise => { +export const get_chapters = async ( + chapter_id: string +): Promise => { const response = await axios.get(url(`chapters/${chapter_id}`)); return response.data.data; -} +}; -export const get_games_chapters = async (game_id: string): Promise => { +export const get_games_chapters = async ( + game_id: string +): Promise => { const response = await axios.get(url(`games/${game_id}`)); return response.data.data; }; export const get_game_maps = async (game_id: string): Promise => { - const response = await axios.get(url(`games/${game_id}/maps`)) + const response = await axios.get(url(`games/${game_id}/maps`)); return response.data.data.maps; }; export const get_search = async (q: string): Promise => { - const response = await axios.get(url(`search?q=${q}`)) + const response = await axios.get(url(`search?q=${q}`)); return response.data.data; }; 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 @@ -import axios from "axios"; -import { url } from "@api/Api"; -import { MapDiscussionContent, UploadRunContent } from "@customTypes/Content"; -import { MapSummary, MapLeaderboard, MapDiscussions, MapDiscussion } from "@customTypes/Map"; +import axios from 'axios'; +import { url } from '@api/Api'; +import { MapDiscussionContent, UploadRunContent } from '@customTypes/Content'; +import { + MapSummary, + MapLeaderboard, + MapDiscussions, + MapDiscussion, +} from '@customTypes/Map'; export const get_map_summary = async (map_id: string): Promise => { - const response = await axios.get(url(`maps/${map_id}/summary`)) + const response = await axios.get(url(`maps/${map_id}/summary`)); return response.data.data; }; -export const get_map_leaderboard = async (map_id: string, page: string): Promise => { - const response = await axios.get(url(`maps/${map_id}/leaderboards?page=${page}`)); +export const get_map_leaderboard = async ( + map_id: string, + page: string +): Promise => { + const response = await axios.get( + url(`maps/${map_id}/leaderboards?page=${page}`) + ); if (!response.data.success) { return undefined; } @@ -25,7 +35,9 @@ export const get_map_leaderboard = async (map_id: string, page: string): Promise return data; }; -export const get_map_discussions = async (map_id: string): Promise => { +export const get_map_discussions = async ( + map_id: string +): Promise => { const response = await axios.get(url(`maps/${map_id}/discussions`)); if (!response.data.data.discussions) { return undefined; @@ -33,74 +45,122 @@ export const get_map_discussions = async (map_id: string): Promise => { - const response = await axios.get(url(`maps/${map_id}/discussions/${discussion_id}`)); +export const get_map_discussion = async ( + map_id: string, + discussion_id: number +): Promise => { + const response = await axios.get( + url(`maps/${map_id}/discussions/${discussion_id}`) + ); if (!response.data.data.discussion) { return undefined; } return response.data.data; }; -export const post_map_discussion = async (token: string, map_id: string, content: MapDiscussionContent): Promise => { - const response = await axios.post(url(`maps/${map_id}/discussions`), { - "title": content.title, - "content": content.content, - }, { - headers: { - "Authorization": token, +export const post_map_discussion = async ( + token: string, + map_id: string, + content: MapDiscussionContent +): Promise => { + const response = await axios.post( + url(`maps/${map_id}/discussions`), + { + title: content.title, + content: content.content, + }, + { + headers: { + Authorization: token, + }, } - }); + ); return response.data.success; }; -export const post_map_discussion_comment = async (token: string, map_id: string, discussion_id: number, comment: string): Promise => { - const response = await axios.post(url(`maps/${map_id}/discussions/${discussion_id}`), { - "comment": comment, - }, { - headers: { - "Authorization": token, +export const post_map_discussion_comment = async ( + token: string, + map_id: string, + discussion_id: number, + comment: string +): Promise => { + const response = await axios.post( + url(`maps/${map_id}/discussions/${discussion_id}`), + { + comment: comment, + }, + { + headers: { + Authorization: token, + }, } - }); + ); return response.data.success; }; -export const delete_map_discussion = async (token: string, map_id: string, discussion_id: number): Promise => { - const response = await axios.delete(url(`maps/${map_id}/discussions/${discussion_id}`), { - headers: { - "Authorization": token, +export const delete_map_discussion = async ( + token: string, + map_id: string, + discussion_id: number +): Promise => { + const response = await axios.delete( + url(`maps/${map_id}/discussions/${discussion_id}`), + { + headers: { + Authorization: token, + }, } - }); + ); return response.data.success; }; -export const post_record = async (token: string, run: UploadRunContent, map_id: number): Promise<[boolean, string]> => { +export const post_record = async ( + token: string, + run: UploadRunContent, + map_id: number +): Promise<[boolean, string]> => { if (run.partner_demo) { - const response = await axios.postForm(url(`maps/${map_id}/record`), { - "host_demo": run.host_demo, - "partner_demo": run.partner_demo, - }, { - headers: { - "Authorization": token, + const response = await axios.postForm( + url(`maps/${map_id}/record`), + { + host_demo: run.host_demo, + partner_demo: run.partner_demo, + }, + { + headers: { + Authorization: token, + }, } - }); + ); return [response.data.success, response.data.message]; } else { - const response = await axios.postForm(url(`maps/${map_id}/record`), { - "host_demo": run.host_demo, - }, { - headers: { - "Authorization": token, + const response = await axios.postForm( + url(`maps/${map_id}/record`), + { + host_demo: run.host_demo, + }, + { + headers: { + Authorization: token, + }, } - }); + ); return [response.data.success, response.data.message]; } -} +}; -export const delete_map_record = async (token: string, map_id: number, record_id: number): Promise => { - const response = await axios.delete(url(`maps/${map_id}/record/${record_id}`), { - headers: { - "Authorization": token, +export const delete_map_record = async ( + token: string, + map_id: number, + record_id: number +): Promise => { + const response = await axios.delete( + url(`maps/${map_id}/record/${record_id}`), + { + headers: { + Authorization: token, + }, } - }); + ); return response.data.success; }; diff --git a/frontend/src/api/Mod.ts b/frontend/src/api/Mod.ts index 1511f8b..69e76c5 100644 --- a/frontend/src/api/Mod.ts +++ b/frontend/src/api/Mod.ts @@ -1,58 +1,86 @@ -import axios from "axios"; -import { url } from "@api/Api"; -import { ModMenuContent } from "@customTypes/Content"; +import axios from 'axios'; +import { url } from '@api/Api'; +import { ModMenuContent } from '@customTypes/Content'; -export const put_map_image = async (token: string, map_id: string, image: string): Promise => { - const response = await axios.put(url(`maps/${map_id}/image`), { - "image": image, - }, { - headers: { - "Authorization": token, +export const put_map_image = async ( + token: string, + map_id: string, + image: string +): Promise => { + const response = await axios.put( + url(`maps/${map_id}/image`), + { + image: image, + }, + { + headers: { + Authorization: token, + }, } - }); + ); return response.data.success; }; -export const post_map_summary = async (token: string, map_id: string, content: ModMenuContent): Promise => { - const response = await axios.post(url(`maps/${map_id}/summary`), { - "category_id": content.category_id, - "user_name": content.name, - "score_count": content.score, - "record_date": content.date, - "showcase": content.showcase, - "description": content.description, - }, { - headers: { - "Authorization": token, +export const post_map_summary = async ( + token: string, + map_id: string, + content: ModMenuContent +): Promise => { + const response = await axios.post( + url(`maps/${map_id}/summary`), + { + category_id: content.category_id, + user_name: content.name, + score_count: content.score, + record_date: content.date, + showcase: content.showcase, + description: content.description, + }, + { + headers: { + Authorization: token, + }, } - }); + ); return response.data.success; }; -export const put_map_summary = async (token: string, map_id: string, content: ModMenuContent): Promise => { - const response = await axios.put(url(`maps/${map_id}/summary`), { - "route_id": content.id, - "user_name": content.name, - "score_count": content.score, - "record_date": content.date, - "showcase": content.showcase, - "description": content.description, - }, { - headers: { - "Authorization": token, +export const put_map_summary = async ( + token: string, + map_id: string, + content: ModMenuContent +): Promise => { + const response = await axios.put( + url(`maps/${map_id}/summary`), + { + route_id: content.id, + user_name: content.name, + score_count: content.score, + record_date: content.date, + showcase: content.showcase, + description: content.description, + }, + { + headers: { + Authorization: token, + }, } - }); + ); return response.data.success; }; -export const delete_map_summary = async (token: string, map_id: string, route_id: number): Promise => { +export const delete_map_summary = async ( + token: string, + map_id: string, + route_id: number +): Promise => { const response = await axios.delete(url(`maps/${map_id}/summary`), { data: { - "route_id": route_id, + route_id: route_id, }, headers: { - "Authorization": token, - } + Authorization: token, + }, }); return response.data.success; }; diff --git a/frontend/src/api/Rankings.ts b/frontend/src/api/Rankings.ts index b8d9bec..9afd999 100644 --- a/frontend/src/api/Rankings.ts +++ b/frontend/src/api/Rankings.ts @@ -1,6 +1,6 @@ -import axios from "axios"; -import { url } from "@api/Api"; -import { Ranking, SteamRanking } from "@customTypes/Ranking"; +import axios from 'axios'; +import { url } from '@api/Api'; +import { Ranking, SteamRanking } from '@customTypes/Ranking'; export const get_official_rankings = async (): Promise => { const response = await axios.get(url(`rankings/lphub`)); diff --git a/frontend/src/api/User.ts b/frontend/src/api/User.ts index 004aa22..4ce21e1 100644 --- a/frontend/src/api/User.ts +++ b/frontend/src/api/User.ts @@ -1,6 +1,6 @@ -import axios from "axios"; -import { url } from "@api/Api"; -import { UserProfile } from "@customTypes/Profile"; +import axios from 'axios'; +import { url } from '@api/Api'; +import { UserProfile } from '@customTypes/Profile'; export const get_user = async (user_id: string): Promise => { const response = await axios.get(url(`users/${user_id}`)); -- cgit v1.2.3