mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: clan cache
This commit is contained in:
1 parent
8fbd1acf4a
commit
87e23673fb
1 file changed
+24
-6
@@ -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<Record<Region, Record<number, string>>>(() => ({
|
||||
com: {},
|
||||
eu: {},
|
||||
}));
|
||||
const clanCache: Record<Region, Record<number, string>> = {
|
||||
com: {},
|
||||
eu: {},
|
||||
asia: {},
|
||||
};
|
||||
const useClanCache = create<Record<Region, Record<number, string | undefined>>>(
|
||||
() => ({
|
||||
asia: {},
|
||||
com: {},
|
||||
eu: {},
|
||||
}),
|
||||
);
|
||||
|
||||
export default function Page() {
|
||||
const usernameCache = useUsernameCache();
|
||||
const clanCache = useClanCache();
|
||||
const [region, setRegion] = useState<Region>('com');
|
||||
// null being the latest season
|
||||
const [season, setSeason] = useState<null | number>(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() {
|
||||
</Select.Root>
|
||||
</Flex>
|
||||
|
||||
<Flex justify="between">
|
||||
<Flex justify="between" wrap="wrap" gap="2">
|
||||
<Flex gap="2">
|
||||
<Popover.Root>
|
||||
<Popover.Trigger>
|
||||
@@ -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}
|
||||
/>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user