fix: session

This commit is contained in:
TrèsAbhi committed 2024-10-21 10:49:06 -05:00
1 parent c92d355484
commit 650dbf66a9
1 file changed
+14 -12
@@ -36,7 +36,6 @@ import {
} from '@radix-ui/themes'; } from '@radix-ui/themes';
import { debounce } from 'lodash-es'; import { debounce } from 'lodash-es';
import { useEffect, useMemo, useRef, useState } from 'react'; import { useEffect, useMemo, useRef, useState } from 'react';
import usePromise from 'react-promise-suspense';
import { PageWrapper } from '../../../components/PageWrapper'; import { PageWrapper } from '../../../components/PageWrapper';
import { TankRowHeaderCell } from '../../../components/TankRowHeaderCell'; import { TankRowHeaderCell } from '../../../components/TankRowHeaderCell';
import { Session, type SessionTracking } from '../../../stores/session'; import { Session, type SessionTracking } from '../../../stores/session';
@@ -64,17 +63,20 @@ function Content() {
const [tankStatsB, setTankStatsB] = useState<IndividualTankStats[] | null>( const [tankStatsB, setTankStatsB] = useState<IndividualTankStats[] | null>(
null, null,
); );
const accountInfo = usePromise( const [accountInfo, setAccountInfo] = useState<
(id?: number) => IndividualAccountInfo | null | undefined
new Promise<IndividualAccountInfo | null>(async (resolve) => { >(undefined);
if (!id) return resolve(null);
resolve( useEffect(() => {
session.tracking ? await getAccountInfo(idToRegion(id), id) : null, (async () => {
); const id = session.tracking ? session.player.id : undefined;
}), if (!id) return setAccountInfo(null);
[session.tracking ? session.player.id : undefined],
); setAccountInfo(
session.tracking ? await getAccountInfo(idToRegion(id), id) : null,
);
})();
}, [session.tracking && session.player.id]);
const delta = useMemo( const delta = useMemo(
() => () =>
session.tracking && tankStatsB session.tracking && tankStatsB
@@ -83,7 +85,7 @@ function Content() {
.map((entry) => { .map((entry) => {
const tank = tankDefinitions.tanks[entry.tank_id]; const tank = tankDefinitions.tanks[entry.tank_id];
const average = tankAverages.averages[tank.id]; const average = tankAverages.averages[tank.id];
const stats = generateStats(entry.all, average.mu); const stats = generateStats(entry.all, average?.mu);
const statsPretty = prettifyStats(stats); const statsPretty = prettifyStats(stats);
return { return {