Files
blitzkit/packages/website/src/components/HomePageHotTanks.tsx
T

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-11-11 12:46:06 -06:00
import { fetchAverageDefinitions, fetchTankDefinitions } from '@blitzkit/core';
import { Box, Flex, Heading } from '@radix-ui/themes';
import { TankopediaPersistent } from '../stores/tankopediaPersistent';
2024-11-16 22:47:12 -06:00
import { TankCard } from './TankCard';
2024-11-11 12:46:06 -06:00
const tankDefinitions = await fetchTankDefinitions();
const averageDefinitions = await fetchAverageDefinitions();
const tanks = Object.values(tankDefinitions.tanks);
const tankAverages = Object.entries(averageDefinitions.averages).map(
([id, average]) => ({
id: Number(id),
...average,
}),
);
// lol don't ask questions
const testTanks = tanks
2024-11-13 10:21:32 -06:00
.filter((tank) => tank.testing)
2024-11-11 12:46:06 -06:00
.sort((a, b) => b.tier - a.tier);
const mostPlayedTanks = tankAverages
.sort((a, b) => b.samples.d_1 - a.samples.d_1)
.map(({ id }) => tankDefinitions.tanks[id])
.filter((tank) => tank !== undefined && !tank.testing);
const popularTanks = [...testTanks, ...mostPlayedTanks].slice(0, 8);
export function HomePageHotTanks() {
return (
<TankopediaPersistent.Provider>
<Content />
</TankopediaPersistent.Provider>
);
}
function Content() {
return (
<Flex direction="column" gap="5" pt="4" pb="8">
<Heading align="center" size="5">
Popular tanks
</Heading>
<Flex justify="center" gap="4" wrap="wrap">
{popularTanks.map((tank) => (
2024-11-12 14:36:55 -06:00
<Box width="7rem" key={tank.id}>
2024-11-11 12:46:06 -06:00
<TankCard tank={tank} />
</Box>
))}
</Flex>
</Flex>
);
}