mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-09 21:51:29 +08:00
refactor: use single client for whole contract on frontend (@fehmer) (#5752)
* refactor: use single client for whole contract on frontend (@fehmer) * review comments
This commit is contained in:
parent
4995f042ac
commit
cfea8eef19
2 changed files with 5 additions and 12 deletions
|
|
@ -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)),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ async function getStatsAndHistogramData(): Promise<void> {
|
|||
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<void> {
|
|||
-1
|
||||
);
|
||||
}
|
||||
const typingStats = await Ape.publicStats.getTypingStats();
|
||||
const typingStats = await Ape.public.getTypingStats();
|
||||
if (typingStats.status === 200) {
|
||||
typingStatsResponseData = typingStats.body.data;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue