feat: upgrade performance

This commit is contained in:
TrèsAbhi committed 2025-09-01 18:16:41 -05:00
1 parent 4efdaaf7c9
commit b6c3fdc4e9
6 files changed
+21 -31

No files matched your search

@@ -1,15 +1,9 @@
import { Flex, Select, Text } from '@radix-ui/themes'; import { Flex, Select, Text } from '@radix-ui/themes';
import { useLocale } from '../../hooks/useLocale'; import { useLocale } from '../../hooks/useLocale';
import { import { Performance, type PlayerCountPeriod } from '../../stores/performance';
TankPerformanceEphemeral,
type PlayerCountPeriod,
} from '../../stores/tankPerformanceEphemeral';
export function PlayerCountControl() { export function PlayerCountControl() {
const playerCountPeriod = TankPerformanceEphemeral.use( const playerCountPeriod = Performance.use((state) => state.playerCountPeriod);
(state) => state.playerCountPeriod,
);
const mutateTankPerformanceSort = TankPerformanceEphemeral.useMutation();
const { strings } = useLocale(); const { strings } = useLocale();
return ( return (
@@ -18,7 +12,7 @@ export function PlayerCountControl() {
<Select.Root <Select.Root
value={playerCountPeriod} value={playerCountPeriod}
onValueChange={(period) => { onValueChange={(period) => {
mutateTankPerformanceSort((draft) => { Performance.mutate((draft) => {
draft.playerCountPeriod = period as PlayerCountPeriod; draft.playerCountPeriod = period as PlayerCountPeriod;
}); });
}} }}
@@ -4,7 +4,7 @@ import { memo } from 'react';
import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions'; import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions';
import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio'; import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio';
import { useLocale } from '../../hooks/useLocale'; import { useLocale } from '../../hooks/useLocale';
import { TankPerformanceEphemeral } from '../../stores/tankPerformanceEphemeral'; import { Performance } from '../../stores/performance';
import { TankRowHeaderCell } from '../TankRowHeaderCell'; import { TankRowHeaderCell } from '../TankRowHeaderCell';
interface TankRowProps { interface TankRowProps {
@@ -17,7 +17,7 @@ export const TankRow = memo<TankRowProps>(
({ tank }) => { ({ tank }) => {
const averages = averageDefinitions.averages[tank.id]; const averages = averageDefinitions.averages[tank.id];
const ratio = useAveragesExclusionRatio(); const ratio = useAveragesExclusionRatio();
const playerCountPeriod = TankPerformanceEphemeral.use( const playerCountPeriod = Performance.use(
(state) => state.playerCountPeriod, (state) => state.playerCountPeriod,
); );
const { locale } = useLocale(); const { locale } = useLocale();
@@ -5,8 +5,8 @@ import { Fragment, Suspense, useEffect, useMemo, useState } from 'react';
import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions'; import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions';
import { awaitableTankDefinitions } from '../../core/awaitables/tankDefinitions'; import { awaitableTankDefinitions } from '../../core/awaitables/tankDefinitions';
import { filterTank } from '../../core/blitzkit/filterTank'; import { filterTank } from '../../core/blitzkit/filterTank';
import { Performance } from '../../stores/performance';
import { $tankFilters } from '../../stores/tankFilters'; import { $tankFilters } from '../../stores/tankFilters';
import { TankPerformanceEphemeral } from '../../stores/tankPerformanceEphemeral';
import { TankPerformanceSort } from '../../stores/tankPerformanceSort'; import { TankPerformanceSort } from '../../stores/tankPerformanceSort';
import type { MaybeSkeletonComponentProps } from '../../types/maybeSkeletonComponentProps'; import type { MaybeSkeletonComponentProps } from '../../types/maybeSkeletonComponentProps';
import { RowLoader } from './RowLoader'; import { RowLoader } from './RowLoader';
@@ -40,10 +40,9 @@ export function Tanks({ skeleton }: MaybeSkeletonComponentProps) {
} }
const sort = TankPerformanceSort.use(); const sort = TankPerformanceSort.use();
const tankPerformancePersistentStore = TankPerformanceEphemeral.useStore();
const filters = useStore($tankFilters); const filters = useStore($tankFilters);
const tanksSorted = useMemo(() => { const tanksSorted = useMemo(() => {
const { playerCountPeriod } = tankPerformancePersistentStore.getState(); const { playerCountPeriod } = Performance.state;
switch (sort.type) { switch (sort.type) {
case 'accuracy': case 'accuracy':
@@ -8,7 +8,7 @@ import { memo, useCallback } from 'react';
import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions'; import { awaitableAverageDefinitions } from '../../core/awaitables/averageDefinitions';
import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio'; import { useAveragesExclusionRatio } from '../../hooks/useAveragesExclusionRatio';
import { useLocale } from '../../hooks/useLocale'; import { useLocale } from '../../hooks/useLocale';
import { TankPerformanceEphemeral } from '../../stores/tankPerformanceEphemeral'; import { Performance } from '../../stores/performance';
import { StickyRowHeaderCell } from '../StickyRowHeaderCell'; import { StickyRowHeaderCell } from '../StickyRowHeaderCell';
interface AverageDefinitionsEntryWithId extends AverageDefinitionsEntry { interface AverageDefinitionsEntryWithId extends AverageDefinitionsEntry {
@@ -23,7 +23,7 @@ const averageDefinitions = await awaitableAverageDefinitions;
export const Total = memo<TotalProps>( export const Total = memo<TotalProps>(
({ tanks }) => { ({ tanks }) => {
const playerCountPeriod = TankPerformanceEphemeral.use( const playerCountPeriod = Performance.use(
(state) => state.playerCountPeriod, (state) => state.playerCountPeriod,
); );
const { strings, locale } = useLocale(); const { strings, locale } = useLocale();
@@ -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<Performance>({
playerCountPeriod: 'd_30',
});
@@ -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<TankPerformanceEphemeral>()(() => ({
playerCountPeriod: 'd_30',
})),
);