aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/api
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2025-10-27 22:12:56 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2025-10-27 23:13:45 +0400
commitdd5ea1b1fcbb21c919a16bc70c6507b097c12f6b (patch)
treeeba2d3b52bc26021ac31d76477e3ac672d1db096 /frontend/src/api
parentfeat/backend: timeline stats endpoint (diff)
downloadlphub-dd5ea1b1fcbb21c919a16bc70c6507b097c12f6b.tar.gz
lphub-dd5ea1b1fcbb21c919a16bc70c6507b097c12f6b.tar.bz2
lphub-dd5ea1b1fcbb21c919a16bc70c6507b097c12f6b.zip
feat/frontend: homepage with timeline and recent scores
Diffstat (limited to 'frontend/src/api')
-rw-r--r--frontend/src/api/Api.ts4
-rw-r--r--frontend/src/api/Stats.ts52
2 files changed, 56 insertions, 0 deletions
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
5import { get_official_rankings, get_unofficial_rankings } from "@api/Rankings"; 5import { get_official_rankings, get_unofficial_rankings } from "@api/Rankings";
6import { 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"; 6import { 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";
7import { delete_map_summary, post_map_summary, put_map_image, put_map_summary } from "@api/Mod"; 7import { delete_map_summary, post_map_summary, put_map_image, put_map_summary } from "@api/Mod";
8import { get_portal_count_history, get_recent_scores } from "@api/Stats";
8import { UploadRunContent } from "@customTypes/Content"; 9import { UploadRunContent } from "@customTypes/Content";
9 10
10// add new api call function entries here 11// add new api call function entries here
@@ -47,6 +48,9 @@ export const API = {
47 put_map_summary: (token: string, map_id: string, content: ModMenuContent) => put_map_summary(token, map_id, content), 48 put_map_summary: (token: string, map_id: string, content: ModMenuContent) => put_map_summary(token, map_id, content),
48 49
49 delete_map_summary: (token: string, map_id: string, route_id: number) => delete_map_summary(token, map_id, route_id), 50 delete_map_summary: (token: string, map_id: string, route_id: number) => delete_map_summary(token, map_id, route_id),
51 // Stats
52 get_portal_count_history: () => get_portal_count_history(),
53 get_recent_scores: () => get_recent_scores(),
50}; 54};
51 55
52const BASE_API_URL: string = import.meta.env.DEV 56const 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 @@
1import axios from "axios";
2import { url } from "./Api";
3
4export interface PortalCountData {
5 date: string;
6 count: number;
7}
8
9export interface RecordsTimelineResponse {
10 timeline_singleplayer: PortalCountData[];
11 timeline_multiplayer: PortalCountData[];
12}
13
14export interface ScoreLog {
15 game: {
16 id: number;
17 name: string;
18 image: string;
19 is_coop: boolean;
20 category_portals: null;
21 };
22 user: {
23 steam_id: string;
24 user_name: string;
25 };
26 map: {
27 id: number;
28 name: string;
29 image: string;
30 is_disabled: boolean;
31 portal_count: number;
32 difficulty: number;
33 };
34 score_count: number;
35}
36
37export async function get_portal_count_history(): Promise<RecordsTimelineResponse | undefined> {
38 const response = await axios.get(url("stats/timeline"));
39 if (!response.data.data) {
40 return undefined;
41 }
42 return response.data.data;
43}
44
45export async function get_recent_scores(): Promise<ScoreLog[]> {
46 const response = await axios.get(url("stats/scores"));
47 if (!response.data.data) {
48 return [];
49 }
50 return response.data.data.scores.slice(0, 5);
51}
52