From b6c3fdc4e90b83991eaaf78d3203a16bd2cb0bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Mon, 1 Sep 2025 18:16:41 -0500 Subject: [PATCH] feat: upgrade performance --- .../components/Performance/PlayerCountControl.tsx | 12 +++--------- .../src/components/Performance/TankRow.tsx | 4 ++-- .../website/src/components/Performance/Tanks.tsx | 5 ++--- .../website/src/components/Performance/Total.tsx | 4 ++-- packages/website/src/stores/performance.ts | 12 ++++++++++++ .../src/stores/tankPerformanceEphemeral.ts | 15 --------------- 6 files changed, 21 insertions(+), 31 deletions(-) create mode 100644 packages/website/src/stores/performance.ts delete mode 100644 packages/website/src/stores/tankPerformanceEphemeral.ts diff --git a/packages/website/src/components/Performance/PlayerCountControl.tsx b/packages/website/src/components/Performance/PlayerCountControl.tsx index aeeb6d8f5..297bb2908 100644 --- a/packages/website/src/components/Performance/PlayerCountControl.tsx +++ b/packages/website/src/components/Performance/PlayerCountControl.tsx @@ -1,15 +1,9 @@ import { Flex, Select, Text } from '@radix-ui/themes'; import { useLocale } from '../../hooks/useLocale'; -import { - TankPerformanceEphemeral, - type PlayerCountPeriod, -} from '../../stores/tankPerformanceEphemeral'; +import { Performance, type PlayerCountPeriod } from '../../stores/performance'; export function PlayerCountControl() { - const playerCountPeriod = TankPerformanceEphemeral.use( - (state) => state.playerCountPeriod, - ); - const mutateTankPerformanceSort = TankPerformanceEphemeral.useMutation(); + const playerCountPeriod = Performance.use((state) => state.playerCountPeriod); const { strings } = useLocale(); return ( @@ -18,7 +12,7 @@ export function PlayerCountControl() { { - mutateTankPerformanceSort((draft) => { + Performance.mutate((draft) => { draft.playerCountPeriod = period as PlayerCountPeriod; }); }} diff --git a/packages/website/src/components/Performance/TankRow.tsx b/packages/website/src/components/Performance/TankRow.tsx index 9c4b9ef4a..9137bdecd 100644 --- a/packages/website/src/components/Performance/TankRow.tsx +++ b/packages/website/src/components/Performance/TankRow.tsx @@ -4,7 +4,7 @@ import { memo } from 'react'; import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions'; import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio'; import { useLocale } from '../../hooks/useLocale'; -import { TankPerformanceEphemeral } from '../../stores/tankPerformanceEphemeral'; +import { Performance } from '../../stores/performance'; import { TankRowHeaderCell } from '../TankRowHeaderCell'; interface TankRowProps { @@ -17,7 +17,7 @@ export const TankRow = memo( ({ tank }) => { const averages = averageDefinitions.averages[tank.id]; const ratio = useAveragesExclusionRatio(); - const playerCountPeriod = TankPerformanceEphemeral.use( + const playerCountPeriod = Performance.use( (state) => state.playerCountPeriod, ); const { locale } = useLocale(); diff --git a/packages/website/src/components/Performance/Tanks.tsx b/packages/website/src/components/Performance/Tanks.tsx index 1267e46ed..e49a40487 100644 --- a/packages/website/src/components/Performance/Tanks.tsx +++ b/packages/website/src/components/Performance/Tanks.tsx @@ -5,8 +5,8 @@ import { Fragment, Suspense, useEffect, useMemo, useState } from 'react'; import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions'; import { awaitableTankDefinitions } from '../../core/awaitables/tankDefinitions'; import { filterTank } from '../../core/blitzkit/filterTank'; +import { Performance } from '../../stores/performance'; import { $tankFilters } from '../../stores/tankFilters'; -import { TankPerformanceEphemeral } from '../../stores/tankPerformanceEphemeral'; import { TankPerformanceSort } from '../../stores/tankPerformanceSort'; import type { MaybeSkeletonComponentProps } from '../../types/maybeSkeletonComponentProps'; import { RowLoader } from './RowLoader'; @@ -40,10 +40,9 @@ export function Tanks({ skeleton }: MaybeSkeletonComponentProps) { } const sort = TankPerformanceSort.use(); - const tankPerformancePersistentStore = TankPerformanceEphemeral.useStore(); const filters = useStore($tankFilters); const tanksSorted = useMemo(() => { - const { playerCountPeriod } = tankPerformancePersistentStore.getState(); + const { playerCountPeriod } = Performance.state; switch (sort.type) { case 'accuracy': diff --git a/packages/website/src/components/Performance/Total.tsx b/packages/website/src/components/Performance/Total.tsx index 5002ee56b..fbe3e1eed 100644 --- a/packages/website/src/components/Performance/Total.tsx +++ b/packages/website/src/components/Performance/Total.tsx @@ -8,7 +8,7 @@ import { memo, useCallback } from 'react'; import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions'; import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio'; import { useLocale } from '../../hooks/useLocale'; -import { TankPerformanceEphemeral } from '../../stores/tankPerformanceEphemeral'; +import { Performance } from '../../stores/performance'; import { StickyRowHeaderCell } from '../StickyRowHeaderCell'; interface AverageDefinitionsEntryWithId extends AverageDefinitionsEntry { @@ -23,7 +23,7 @@ const averageDefinitions = await awaitableAverageDefinitions; export const Total = memo( ({ tanks }) => { - const playerCountPeriod = TankPerformanceEphemeral.use( + const playerCountPeriod = Performance.use( (state) => state.playerCountPeriod, ); const { strings, locale } = useLocale(); diff --git a/packages/website/src/stores/performance.ts b/packages/website/src/stores/performance.ts new file mode 100644 index 000000000..6584f0ace --- /dev/null +++ b/packages/website/src/stores/performance.ts @@ -0,0 +1,12 @@ +import type { Samples } from '@blitzkit/core'; +import { Varuna } from 'varuna'; + +export interface Performance { + playerCountPeriod: PlayerCountPeriod; +} + +export type PlayerCountPeriod = keyof Samples; + +export const Performance = new Varuna({ + playerCountPeriod: 'd_30', +}); diff --git a/packages/website/src/stores/tankPerformanceEphemeral.ts b/packages/website/src/stores/tankPerformanceEphemeral.ts deleted file mode 100644 index 1ec8714d3..000000000 --- a/packages/website/src/stores/tankPerformanceEphemeral.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { Samples } from '@blitzkit/core'; -import { create } from 'zustand'; -import { createContextualStore } from '../core/zustand/createContextualStore'; - -export interface TankPerformanceEphemeral { - playerCountPeriod: PlayerCountPeriod; -} - -export type PlayerCountPeriod = keyof Samples; - -export const TankPerformanceEphemeral = createContextualStore(() => - create()(() => ({ - playerCountPeriod: 'd_30', - })), -);