filterbar wip

This commit is contained in:
Robin Appelman 2023-04-11 23:06:48 +02:00
commit e5c9aeb7fe
15 changed files with 1905 additions and 420 deletions

38
script/api.ts Normal file
View file

@ -0,0 +1,38 @@
export type SteamId = string;
export interface SteamUser {
id: number;
steamid: SteamId;
name: string;
}
export class Api {
private base: string;
constructor(base: string) {
this.base = base;
}
getApiUrl(url) {
return this.base + url;
}
request(url, params = {}, json = true): Promise<string | any> {
let queryParams = new URLSearchParams(params);
return fetch(this.getApiUrl(url) + '?' + queryParams)
.then((response) => {
if (json) {
return response.json()
} else {
return response.text();
}
});
}
async searchPlayer(query: string): Promise<SteamUser[]> {
if (query.length < 2) {
return [];
}
return await this.request('users/search', {query}) as SteamUser[];
}
}