perf: reactive updates

This commit is contained in:
TrèsAbhi committed 2025-10-14 20:15:00 -05:00
1 parent 222b690fba
commit ff4a87e5b8
3 files changed
+48 -47

No files matched your search

@@ -1,11 +1,9 @@
import { Box, Flex } from "@radix-ui/themes";
import { useLocale } from "../hooks/useLocale";
import { CurrentlyPlaying } from "./CurrentlyPlaying";
import { PlaylistActions } from "./PlaylistActions";
import { PlaylistTable } from "./PlaylistTable";
export function PlaylistOrder() {
return (
<Flex
direction="column"
@@ -1,5 +1,6 @@
import { MinusCircledIcon } from "@radix-ui/react-icons";
import { Checkbox, IconButton, Table } from "@radix-ui/themes";
import { memo } from "react";
import { useLocale } from "../hooks/useLocale";
import { Playlist, type PlaylistEntry } from "../stores/playlist";
import { TankRowHeaderCell } from "./TankRowHeaderCell";
@@ -8,55 +9,57 @@ interface Props extends PlaylistEntry {
index: number;
}
export function PlaylistTankEntry({
tank,
checked,
last,
battles,
index,
}: Props) {
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;
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;
return (
<Table.Row>
<Table.Cell>{index + 1}</Table.Cell>
return (
<Table.Row>
<Table.Cell>{index + 1}</Table.Cell>
<TankRowHeaderCell tank={tank} />
<TankRowHeaderCell tank={tank} />
<Table.Cell>
{lastDays
? rtf.format(Math.floor(lastDays - nowDays), "day")
: strings.website.tools.playlist.table.never}
</Table.Cell>
<Table.Cell>
{lastDays
? rtf.format(Math.floor(lastDays - nowDays), "day")
: strings.website.tools.playlist.table.never}
</Table.Cell>
<Table.Cell>{battles}</Table.Cell>
<Table.Cell>{battles}</Table.Cell>
<Table.Cell
onClick={() => {
Playlist.mutate((draft) => {
draft.list![index].checked = !checked;
});
}}
>
<Checkbox variant="classic" checked={checked} />
</Table.Cell>
<Table.Cell>
<IconButton
variant="ghost"
size="1"
<Table.Cell
onClick={() => {
Playlist.mutate((draft) => {
draft.list!.splice(index, 1);
draft.list![index].checked = !checked;
});
}}
>
<MinusCircledIcon />
</IconButton>
</Table.Cell>
</Table.Row>
);
}
<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
);
@@ -16,7 +16,7 @@ export function Page({
locale,
skeleton,
}: Props & MaybeSkeletonComponentProps) {
const list = Playlist.use((state) => state.list);
const generated = Playlist.use((state) => state.list !== undefined);
const wargaming = App.use((state) => state.logins.wargaming);
useEffect(() => {
@@ -30,8 +30,8 @@ export function Page({
return (
<LocaleProvider locale={locale}>
<PageWrapper color="tomato" direction="row" maxWidth="unset" p="0">
{!list && <PlaylistGenerator />}
{list && <PlaylistOrder />}
{!generated && <PlaylistGenerator />}
{generated && <PlaylistOrder />}
</PageWrapper>
</LocaleProvider>
);