Skip to content

Commit

Permalink
fix: session
Browse files Browse the repository at this point in the history
  • Loading branch information
tresabhi committed Oct 21, 2024
1 parent c92d355 commit 650dbf6
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/website/src/pages/tools/session/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
} from '@radix-ui/themes';
import { debounce } from 'lodash-es';
import { useEffect, useMemo, useRef, useState } from 'react';
import usePromise from 'react-promise-suspense';
import { PageWrapper } from '../../../components/PageWrapper';
import { TankRowHeaderCell } from '../../../components/TankRowHeaderCell';
import { Session, type SessionTracking } from '../../../stores/session';
Expand Down Expand Up @@ -64,17 +63,20 @@ function Content() {
const [tankStatsB, setTankStatsB] = useState<IndividualTankStats[] | null>(
null,
);
const accountInfo = usePromise(
(id?: number) =>
new Promise<IndividualAccountInfo | null>(async (resolve) => {
if (!id) return resolve(null);

resolve(
session.tracking ? await getAccountInfo(idToRegion(id), id) : null,
);
}),
[session.tracking ? session.player.id : undefined],
);
const [accountInfo, setAccountInfo] = useState<
IndividualAccountInfo | null | undefined
>(undefined);

useEffect(() => {
(async () => {
const id = session.tracking ? session.player.id : undefined;
if (!id) return setAccountInfo(null);

setAccountInfo(
session.tracking ? await getAccountInfo(idToRegion(id), id) : null,
);
})();
}, [session.tracking && session.player.id]);
const delta = useMemo(
() =>
session.tracking && tankStatsB
Expand All @@ -83,7 +85,7 @@ function Content() {
.map((entry) => {
const tank = tankDefinitions.tanks[entry.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);

return {
Expand Down

0 comments on commit 650dbf6

Please sign in to comment.