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

107 lines
2.9 KiB
TypeScript
Raw Normal View History

2025-10-14 21:36:37 -05:00
import {
MinusCircledIcon,
TriangleDownIcon,
TriangleUpIcon,
} from "@radix-ui/react-icons";
import { Checkbox, Flex, IconButton, Table, Text } from "@radix-ui/themes";
2025-10-14 20:15:00 -05:00
import { memo } from "react";
2026-09-23 10:25:47 -05:00
import { api } from "../api/dynamic";
2025-10-14 12:11:31 -05:00
import { useLocale } from "../hooks/useLocale";
import { Playlist, type PlaylistEntry } from "../stores/playlist";
2025-10-14 11:32:43 -05:00
import { TankRowHeaderCell } from "./TankRowHeaderCell";
2025-10-14 12:11:31 -05:00
interface Props extends PlaylistEntry {
2025-10-14 11:32:43 -05:00
index: number;
}
2026-08-30 14:26:08 -05:00
const tankDefinitions = await api.tanks();
2025-10-14 21:36:37 -05:00
2025-10-14 20:15:00 -05:00
export const PlaylistTankEntry = memo<Props>(
2025-10-14 21:36:37 -05:00
({ id, checked, then, now, index }) => {
2025-10-14 20:15:00 -05:00
const { locale, strings } = useLocale();
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
2025-10-14 21:36:37 -05:00
const dateNow = Date.now();
const tank = tankDefinitions.tanks[id];
2025-10-14 12:11:31 -05:00
2025-10-14 20:15:00 -05:00
return (
<Table.Row>
<Table.Cell>{index + 1}</Table.Cell>
2025-10-14 12:11:31 -05:00
2025-10-14 20:15:00 -05:00
<Table.Cell
2025-10-14 12:11:31 -05:00
onClick={() => {
Playlist.mutate((draft) => {
2025-10-14 20:15:00 -05:00
draft.list![index].checked = !checked;
2025-10-14 12:11:31 -05:00
});
}}
2025-10-14 11:32:43 -05:00
>
2025-10-14 21:36:37 -05:00
<Checkbox
2025-10-14 21:53:58 -05:00
size="3"
2025-10-14 21:36:37 -05:00
variant="classic"
checked={
(checked === undefined &&
now &&
then &&
now.battles > then.battles) ||
checked
}
/>
2025-10-14 20:15:00 -05:00
</Table.Cell>
<Table.Cell>
<IconButton
variant="ghost"
size="1"
onClick={() => {
Playlist.mutate((draft) => {
draft.list!.splice(index, 1);
});
}}
>
<MinusCircledIcon />
</IconButton>
</Table.Cell>
2025-10-14 21:36:37 -05:00
<TankRowHeaderCell tank={tank} />
<Table.Cell>
{now && then && now.battles !== then.battles ? (
<Flex gap="2">
<Text color="green">
<Flex align="center">
<TriangleUpIcon />
{now.wins - then.wins}
</Flex>
</Text>
<Text color="tomato">
<Flex align="center">
<TriangleDownIcon />
{now.battles - then.battles - now.wins + then.wins}
</Flex>
</Text>
</Flex>
) : (
strings.website.tools.playlist.table.unrecorded
)}
</Table.Cell>
<Table.Cell>
{now?.battles ?? strings.website.tools.playlist.table.unrecorded}
</Table.Cell>
<Table.Cell>
{now && now.last !== 0
? rtf.format(
Math.ceil((now.last - dateNow / 1000) / (60 * 60 * 24)),
2026-08-04 20:31:49 -05:00
"day",
2025-10-14 21:36:37 -05:00
)
: strings.website.tools.playlist.table.unrecorded}
</Table.Cell>
2025-10-14 20:15:00 -05:00
</Table.Row>
);
},
(a, b) =>
a.checked === b.checked &&
2025-10-14 21:36:37 -05:00
a.then?.battles === b.then?.battles &&
2026-08-04 20:31:49 -05:00
a.index === b.index,
2025-10-14 20:15:00 -05:00
);