Skip to content

Commit

Permalink
fix: first time tank deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
tresabhi committed May 3, 2024
1 parent 15bec37 commit ea1eeb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/app/tools/session/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { tankAverages } from '../../../core/blitzstars/tankAverages';
import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
import { useWideFormat } from '../../../hooks/useWideFormat';
import { theme } from '../../../stitches.config';
import { useApp } from '../../../stores/app';
import mutateSession, {
SessionTracking,
useSession,
Expand All @@ -64,7 +63,6 @@ export default function Page() {
useState(false);
const input = useRef<HTMLInputElement>(null);
const session = useSession();
const login = useApp((state) => state.login);
const [tankStatsB, setTankStatsB] = useState<IndividualTankStats[] | null>(
null,
);
Expand All @@ -83,7 +81,7 @@ export default function Page() {
const delta = useMemo(
() =>
session.tracking && tankStatsB
? deltaTankStats(session.player.stats, tankStatsB)
? deltaTankStats([], tankStatsB)
.sort((a, b) => b.last_battle_time - a.last_battle_time)
.map((entry) => {
const tank = awaitedTankDefinitions[entry.tank_id];
Expand Down
9 changes: 6 additions & 3 deletions src/core/statistics/deltaTankStats.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { IndividualTankStats } from '../../types/tanksStats';
import {
emptyIndividualTankStats,
IndividualTankStats,
} from '../../types/tanksStats';

export function deltaTankStats(
tanksA: IndividualTankStats[],
tanksB: IndividualTankStats[],
) {
return tanksB
.map((b) => {
const a = tanksA.find((a) => a.tank_id === b.tank_id);
if (!a) return null;
const a =
tanksA.find((a) => a.tank_id === b.tank_id) ?? emptyIndividualTankStats;

return {
account_id: b.account_id,
Expand Down

0 comments on commit ea1eeb4

Please sign in to comment.