some more styling to the frontend
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { steam2ToSteam64 } from './steam';
|
||||
|
||||
export interface SteamSummary {
|
||||
avatarUrl: string;
|
||||
personaName: string | null;
|
||||
@@ -92,3 +94,28 @@ export async function getSteamSummariesBatch(
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches avatarUrl to any list of objects that have a `steamid` (Steam2
|
||||
* format) field — the shared enrichment step used everywhere a list of
|
||||
* players gets rendered, so every list in the app shows avatars
|
||||
* consistently without duplicating the batch-fetch/fallback logic per call
|
||||
* site.
|
||||
*/
|
||||
export async function attachAvatars<T extends { steamid: string }>(
|
||||
players: T[],
|
||||
): Promise<(T & { avatarUrl: string })[]> {
|
||||
const steam64ByPlayer = new Map<string, string>();
|
||||
for (const p of players) {
|
||||
const id64 = steam2ToSteam64(p.steamid);
|
||||
if (id64) steam64ByPlayer.set(p.steamid, id64);
|
||||
}
|
||||
|
||||
const avatars = await getSteamSummariesBatch([...steam64ByPlayer.values()]);
|
||||
|
||||
return players.map((p) => {
|
||||
const id64 = steam64ByPlayer.get(p.steamid);
|
||||
const avatarUrl = (id64 && avatars.get(id64)?.avatarUrl) || DEFAULT_AVATAR_URL;
|
||||
return { ...p, avatarUrl };
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user