some more styling to the frontend

This commit is contained in:
jenz
2026-08-24 21:52:29 +02:00
parent 28b4e957ea
commit 09107047b9
17 changed files with 275 additions and 147 deletions
@@ -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 };
});
}