From 792d24615159c97a673cba0b2ebb8e970c57df0c Mon Sep 17 00:00:00 2001 From: maxswa Date: Fri, 14 Jun 2019 10:47:36 -0400 Subject: [PATCH] Add URL builders --- src/utils/helpers.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 20f23b4..4b28d1b 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,5 +1,30 @@ -import { Gamemode } from '../types'; -import { BASE_URL, GAMEMODE_URL, STATS_URL } from './constants'; +import { Gamemode, Category } from '../types'; +import { + BASE_URL, + GAMEMODE_URL, + STATS_URL, + SCORES_URL, + SKILLS, + OTHER, +} from './constants'; export const getStatsURL = (gamemode: Gamemode, rsn: string) => `${BASE_URL}${GAMEMODE_URL[gamemode]}${STATS_URL}${encodeURIComponent(rsn)}`; + +export const getPlayerTableURL = (gamemode: Gamemode, rsn: string) => + `${BASE_URL}${ + GAMEMODE_URL[gamemode] + }${SCORES_URL}table=0&user=${encodeURIComponent(rsn)}`; + +export const getHiscoresPageURL = ( + gamemode: Gamemode, + category: Category, + page: number +) => { + const table = [...SKILLS, ...OTHER]; + return `${BASE_URL}${GAMEMODE_URL[gamemode]}${SCORES_URL}${ + table.includes(category) + ? `table=${table.indexOf(category)}` + : `category_type=1&table=${OTHER.indexOf(category)}` + }&page=${page}`; +};