From 87e23673fbfd7979b979d189cf06f3fa0673ead1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:31:03 -0500 Subject: [PATCH] feat: clan cache --- src/app/tools/ratings/page.tsx | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/app/tools/ratings/page.tsx b/src/app/tools/ratings/page.tsx index e4c18818c..a46a78fa2 100644 --- a/src/app/tools/ratings/page.tsx +++ b/src/app/tools/ratings/page.tsx @@ -18,6 +18,7 @@ import * as Leaderboard from '../../../components/Leaderboard'; import PageWrapper from '../../../components/PageWrapper'; import { REGIONS, REGION_NAMES, Region } from '../../../constants/regions'; import { getAccountInfo } from '../../../core/blitz/getAccountInfo'; +import { getClanAccountInfo } from '../../../core/blitz/getClanAccountInfo'; import getRatingsInfo from '../../../core/blitz/getRatingsInfo'; import getArchivedRatingsInfoAPI from '../../../core/blitzkrieg/getArchivedRatingsInfoAPI'; import { getArchivedRatingsLeaderboardAPI } from '../../../core/blitzkrieg/getArchivedRatingsLeaderboardAPI'; @@ -32,14 +33,17 @@ const useUsernameCache = create>>(() => ({ com: {}, eu: {}, })); -const clanCache: Record> = { - com: {}, - eu: {}, - asia: {}, -}; +const useClanCache = create>>( + () => ({ + asia: {}, + com: {}, + eu: {}, + }), +); export default function Page() { const usernameCache = useUsernameCache(); + const clanCache = useClanCache(); const [region, setRegion] = useState('com'); // null being the latest season const [season, setSeason] = useState(null); @@ -90,6 +94,19 @@ export default function Page() { ); }); }); + + getClanAccountInfo(region, ids, ['clan']).then((data) => { + data.map((player) => { + useClanCache.setState( + produce((draft) => { + if (player) { + draft[region][player.account_id] = + player.clan?.tag ?? undefined; + } + }), + ); + }); + }); } } @@ -151,7 +168,7 @@ export default function Page() { - + @@ -278,6 +295,7 @@ export default function Page() { } position={page * ROWS_PER_PAGE + index + 1} score={player.score} + clan={clanCache[region][player.id]} key={player.id} /> ))}