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

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-10-14 12:11:31 -05:00
import { MinusCircledIcon } from "@radix-ui/react-icons";
import { Checkbox, IconButton, Table } from "@radix-ui/themes";
2025-10-14 20:15:00 -05:00
import { memo } from "react";
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;
}
2025-10-14 20:15:00 -05:00
export const PlaylistTankEntry = memo<Props>(
({ tank, checked, last, battles, index }) => {
const { locale, strings } = useLocale();
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
const nowDays = Date.now() / (1000 * 60 * 60 * 24);
const lastDays = last ? last / (60 * 60 * 24) : undefined;
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
<TankRowHeaderCell tank={tank} />
2025-10-14 12:11:31 -05:00
2025-10-14 20:15:00 -05:00
<Table.Cell>
{lastDays
? rtf.format(Math.floor(lastDays - nowDays), "day")
: strings.website.tools.playlist.table.never}
</Table.Cell>
2025-10-14 12:11:31 -05:00
2025-10-14 20:15:00 -05:00
<Table.Cell>{battles}</Table.Cell>
2025-10-14 12:19:28 -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 20:15:00 -05:00
<Checkbox variant="classic" checked={checked} />
</Table.Cell>
<Table.Cell>
<IconButton
variant="ghost"
size="1"
onClick={() => {
Playlist.mutate((draft) => {
draft.list!.splice(index, 1);
});
}}
>
<MinusCircledIcon />
</IconButton>
</Table.Cell>
</Table.Row>
);
},
(a, b) =>
a.checked === b.checked &&
a.battles === b.battles &&
a.last === b.last &&
a.wins === b.wins &&
a.index === b.index
);