From cfea8eef19f925a2d918e9ce3cd1eb0aadf3a955 Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Fri, 9 Aug 2024 22:07:09 +0200 Subject: [PATCH] refactor: use single client for whole contract on frontend (@fehmer) (#5752) * refactor: use single client for whole contract on frontend (@fehmer) * review comments --- frontend/src/ts/ape/index.ts | 13 +++---------- frontend/src/ts/pages/about.ts | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/frontend/src/ts/ape/index.ts b/frontend/src/ts/ape/index.ts index 1d14030a0..46ddac7b3 100644 --- a/frontend/src/ts/ape/index.ts +++ b/frontend/src/ts/ape/index.ts @@ -2,29 +2,22 @@ import endpoints from "./endpoints"; import { buildHttpClient } from "./adapters/axios-adapter"; import { envConfig } from "../constants/env-config"; import { buildClient } from "./adapters/ts-rest-adapter"; -import { configsContract } from "@monkeytype/contracts/configs"; -import { presetsContract } from "@monkeytype/contracts/presets"; -import { apeKeysContract } from "@monkeytype/contracts/ape-keys"; -import { psasContract } from "@monkeytype/contracts/psas"; -import { publicContract } from "@monkeytype/contracts/public"; +import { contract } from "@monkeytype/contracts"; const API_PATH = ""; const BASE_URL = envConfig.backendUrl; const API_URL = `${BASE_URL}${API_PATH}`; const httpClient = buildHttpClient(API_URL, 10_000); +const tsRestClient = buildClient(contract, BASE_URL, 10_000); // API Endpoints const Ape = { + ...tsRestClient, users: new endpoints.Users(httpClient), - configs: buildClient(configsContract, BASE_URL, 10_000), results: new endpoints.Results(httpClient), - psas: buildClient(psasContract, BASE_URL, 10_000), quotes: new endpoints.Quotes(httpClient), leaderboards: new endpoints.Leaderboards(httpClient), - presets: buildClient(presetsContract, BASE_URL, 10_000), - publicStats: buildClient(publicContract, BASE_URL, 10_000), - apeKeys: buildClient(apeKeysContract, BASE_URL, 10_000), configuration: new endpoints.Configuration(httpClient), dev: new endpoints.Dev(buildHttpClient(API_URL, 240_000)), }; diff --git a/frontend/src/ts/pages/about.ts b/frontend/src/ts/pages/about.ts index af3328ca7..df85802de 100644 --- a/frontend/src/ts/pages/about.ts +++ b/frontend/src/ts/pages/about.ts @@ -100,7 +100,7 @@ async function getStatsAndHistogramData(): Promise { return; } - const speedStats = await Ape.publicStats.getSpeedHistogram({ + const speedStats = await Ape.public.getSpeedHistogram({ query: { language: "english", mode: "time", @@ -115,7 +115,7 @@ async function getStatsAndHistogramData(): Promise { -1 ); } - const typingStats = await Ape.publicStats.getTypingStats(); + const typingStats = await Ape.public.getTypingStats(); if (typingStats.status === 200) { typingStatsResponseData = typingStats.body.data; } else {