Files
blitzkit/src/app/tools/statistics/components/Day.tsx
T

105 lines
3.0 KiB
TypeScript
Raw Normal View History

2024-04-16 19:36:49 -05:00
import { CaretDownIcon, CaretRightIcon } from '@radix-ui/react-icons';
import { Button, Flex, Table, Text } from '@radix-ui/themes';
import { random } from 'lodash';
import { use, useMemo, useState } from 'react';
import { tankDefinitions } from '../../../../core/blitzkrieg/tankDefinitions';
import { tankIcon } from '../../../../core/blitzkrieg/tankIcon';
interface DayProps {
offset: number;
}
export function Day({ offset }: DayProps) {
const awaitedTankDefinitions = use(tankDefinitions);
const tanksList = useMemo(
() => Object.values(awaitedTankDefinitions),
[awaitedTankDefinitions],
);
const [expanded, setExpanded] = useState(true);
const time = new Date(Date.now() - offset * 24 * 60 * 60 * 1000);
const tanks = tanksList
2024-04-16 21:49:30 -05:00
.filter((tank) => tank.tier === 10)
2024-04-16 19:36:49 -05:00
.sort(() => Math.random() - 0.5)
.slice(0, random(2, 5));
return (
<>
<Table.Row>
<Table.RowHeaderCell>
<Button
2024-04-16 21:49:30 -05:00
style={{
width: '100%',
}}
2024-04-16 19:36:49 -05:00
variant="ghost"
onClick={() => setExpanded((state) => !state)}
>
2024-04-16 21:49:30 -05:00
<Flex
align="center"
gap="1"
style={{
width: '100%',
}}
>
2024-04-16 19:36:49 -05:00
{expanded ? <CaretDownIcon /> : <CaretRightIcon />}
2024-04-16 21:49:30 -05:00
{time.toLocaleString('default', {
month: 'short',
day: 'numeric',
})}
2024-04-16 19:36:49 -05:00
</Flex>
</Button>
</Table.RowHeaderCell>
<Table.Cell align="right">{random(1, 10)}</Table.Cell>
<Table.Cell align="right">
{random(60, 80, true).toFixed(0)}%
</Table.Cell>
</Table.Row>
{expanded &&
tanks.map((tank) => (
<Table.Row
key={tank.id}
style={{
overflow: 'hidden',
}}
>
<Table.RowHeaderCell
style={{
paddingLeft: 32,
position: 'relative',
overflowY: 'hidden',
}}
>
2024-04-16 21:58:08 -05:00
<img
src={tankIcon(tank.id)}
2024-04-16 19:36:49 -05:00
style={{
position: 'absolute',
2024-04-16 21:58:08 -05:00
width: 128 + 32,
2024-04-16 19:36:49 -05:00
height: '200%',
top: '-50%',
2024-04-16 21:49:30 -05:00
left: 0,
2024-04-16 21:58:08 -05:00
boxShadow: 'inset 128px 0 64px -64px #00000040',
objectFit: 'contain',
objectPosition: '50% 50%',
overflow: 'hidden',
}}
/>
<Text
style={{
position: 'relative',
textWrap: 'nowrap',
textShadow: 'black 0 0 4px',
2024-04-16 21:49:30 -05:00
}}
>
2024-04-16 21:58:08 -05:00
{tank.name}
</Text>
2024-04-16 19:36:49 -05:00
</Table.RowHeaderCell>
<Table.Cell align="right">{random(1, 10)}</Table.Cell>
<Table.Cell align="right">
{random(60, 80, true).toFixed(0)}%
</Table.Cell>
</Table.Row>
))}
</>
);
}