Skip to content

Commit

Permalink
refactor: move config values
Browse files Browse the repository at this point in the history
  • Loading branch information
dominickolbe committed Oct 28, 2021
1 parent 83dabc9 commit 5713d77
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 0 additions & 5 deletions packages/pubg-frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@ export const APP_NAME = process.env.REACT_APP_NAME ?? "APP_NAME_MISSING";

export const API_BASE = process.env.REACT_APP_API_URL;

export const matchRequestDefaults = {
limit: 50,
offset: 0,
};

// 5min
export const PLAYER_VIEW_UPDATE_INTERVAL = 1000 * 60 * 5;
6 changes: 3 additions & 3 deletions packages/pubg-frontend/src/views/Player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { view } from "@risingstack/react-easy-state";
import { formatDistanceToNow, parseISO } from "date-fns";
import { MatchesRequest } from "pubg-model/types/Match";
import { PlayerRequest } from "pubg-model/types/Player";
import { PLAYER_MATCHES_REQUEST_DEFAULTS } from "pubg-utils/src";
import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { ApiController } from "../../components/ApiController";
Expand All @@ -27,7 +28,6 @@ import {
PlayerStatsCardLoading,
} from "../../components/PlayerStatsCard";
import { rootstore } from "../../components/store";
import { matchRequestDefaults } from "../../constants";
import { usePageview } from "../../services/Tracking/usePageview";
import { generateTotalStats } from "../../utils";

Expand Down Expand Up @@ -71,8 +71,8 @@ export const Player = view(() => {
setMatches(null);
const response = await ApiController.getPlayerMatches(
id,
matchRequestDefaults.limit,
matchRequestDefaults.offset
PLAYER_MATCHES_REQUEST_DEFAULTS.LIMIT,
PLAYER_MATCHES_REQUEST_DEFAULTS.OFFSET
);
if (abortCtrl.signal.aborted) return;
if (response.ok) setMatches(response.val);
Expand Down
9 changes: 7 additions & 2 deletions packages/pubg-server/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
HTTP_STATUS_BAD_REQUEST,
HTTP_STATUS_NOT_FOUND,
HTTP_STATUS_TOO_MANY_REQUESTS,
PLAYER_MATCHES_REQUEST_DEFAULTS,
} from "pubg-utils/src";
import * as rt from "runtypes";
import { ON_THE_FLY_UPDATE_INTERVAL } from "../constants";
Expand Down Expand Up @@ -134,8 +135,12 @@ export const setUpApi = (params: { prefix: string }) => {
offset: rt.String.Or(rt.Undefined),
})
.check(ctx.query);
const limit = parseInt(query.limit || "50");
const offset = parseInt(query.offset || "0");
const limit = parseInt(
query.limit || PLAYER_MATCHES_REQUEST_DEFAULTS.LIMIT.toString()
);
const offset = parseInt(
query.offset || PLAYER_MATCHES_REQUEST_DEFAULTS.OFFSET.toString()
);
const matches = await PlayerDbController.findMatches(
{ name: ctx.params.id },
limit,
Expand Down
5 changes: 5 additions & 0 deletions packages/pubg-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ export const generateNewStatsObj = () => {
squadfpp: { ...STATS_OBJ },
};
};

export const PLAYER_MATCHES_REQUEST_DEFAULTS = {
LIMIT: 100,
OFFSET: 0,
};

0 comments on commit 5713d77

Please sign in to comment.