From dd5ea1b1fcbb21c919a16bc70c6507b097c12f6b Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 27 Oct 2025 22:12:56 +0300 Subject: feat/frontend: homepage with timeline and recent scores --- frontend/src/api/Api.ts | 4 ++++ frontend/src/api/Stats.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 frontend/src/api/Stats.ts (limited to 'frontend/src/api') diff --git a/frontend/src/api/Api.ts b/frontend/src/api/Api.ts index dd5076a..4385f2c 100644 --- a/frontend/src/api/Api.ts +++ b/frontend/src/api/Api.ts @@ -5,6 +5,7 @@ import { get_games, get_chapters, get_games_chapters, get_game_maps, get_search import { get_official_rankings, get_unofficial_rankings } from "@api/Rankings"; import { get_map_summary, get_map_leaderboard, get_map_discussions, get_map_discussion, post_map_discussion, post_map_discussion_comment, delete_map_discussion, post_record, delete_map_record } from "@api/Maps"; import { delete_map_summary, post_map_summary, put_map_image, put_map_summary } from "@api/Mod"; +import { get_portal_count_history, get_recent_scores } from "@api/Stats"; import { UploadRunContent } from "@customTypes/Content"; // add new api call function entries here @@ -47,6 +48,9 @@ export const API = { put_map_summary: (token: string, map_id: string, content: ModMenuContent) => put_map_summary(token, map_id, content), delete_map_summary: (token: string, map_id: string, route_id: number) => delete_map_summary(token, map_id, route_id), + // Stats + get_portal_count_history: () => get_portal_count_history(), + get_recent_scores: () => get_recent_scores(), }; const BASE_API_URL: string = import.meta.env.DEV diff --git a/frontend/src/api/Stats.ts b/frontend/src/api/Stats.ts new file mode 100644 index 0000000..21654b5 --- /dev/null +++ b/frontend/src/api/Stats.ts @@ -0,0 +1,52 @@ +import axios from "axios"; +import { url } from "./Api"; + +export interface PortalCountData { + date: string; + count: number; +} + +export interface RecordsTimelineResponse { + timeline_singleplayer: PortalCountData[]; + timeline_multiplayer: PortalCountData[]; +} + +export interface ScoreLog { + game: { + id: number; + name: string; + image: string; + is_coop: boolean; + category_portals: null; + }; + user: { + steam_id: string; + user_name: string; + }; + map: { + id: number; + name: string; + image: string; + is_disabled: boolean; + portal_count: number; + difficulty: number; + }; + score_count: number; +} + +export async function get_portal_count_history(): Promise { + const response = await axios.get(url("stats/timeline")); + if (!response.data.data) { + return undefined; + } + return response.data.data; +} + +export async function get_recent_scores(): Promise { + const response = await axios.get(url("stats/scores")); + if (!response.data.data) { + return []; + } + return response.data.data.scores.slice(0, 5); +} + -- cgit v1.2.3