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

62 lines
1.5 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";
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 12:19:28 -05:00
export function PlaylistTankEntry({
tank,
checked,
last,
battles,
index,
}: Props) {
2025-10-14 12:11:31 -05:00
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 11:32:43 -05:00
return (
<Table.Row>
2025-10-14 12:11:31 -05:00
<Table.Cell>{index + 1}</Table.Cell>
<TankRowHeaderCell tank={tank} />
<Table.Cell>
{lastDays
? rtf.format(Math.floor(lastDays - nowDays), "day")
: strings.website.tools.playlist.table.never}
</Table.Cell>
2025-10-14 12:19:28 -05:00
<Table.Cell>{battles}</Table.Cell>
2025-10-14 11:32:43 -05:00
<Table.Cell
onClick={() => {
Playlist.mutate((draft) => {
draft.list![index].checked = !checked;
});
}}
>
<Checkbox variant="classic" checked={checked} />
</Table.Cell>
<Table.Cell>
2025-10-14 12:11:31 -05:00
<IconButton
variant="ghost"
size="1"
onClick={() => {
Playlist.mutate((draft) => {
draft.list!.splice(index, 1);
});
}}
2025-10-14 11:32:43 -05:00
>
2025-10-14 12:11:31 -05:00
<MinusCircledIcon />
</IconButton>
2025-10-14 11:32:43 -05:00
</Table.Cell>
</Table.Row>
);
}