mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fix: use effect deps
This commit is contained in:
1 parent
0339979f9f
commit
1990322d6d
1 file changed
+73
-62
@@ -68,64 +68,6 @@ export default function Page() {
|
|||||||
| undefined
|
| undefined
|
||||||
>(undefined);
|
>(undefined);
|
||||||
|
|
||||||
async function recalculateDiff() {
|
|
||||||
if (session.isTracking) {
|
|
||||||
const { id, region } = session;
|
|
||||||
const careerRaw = await getWargamingResponse<TanksStats>(
|
|
||||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
|
||||||
);
|
|
||||||
const career = careerRaw[id].reduce<Record<number, IndividualTankStats>>(
|
|
||||||
(accumulator, curr) => ({
|
|
||||||
...accumulator,
|
|
||||||
[curr.tank_id]: curr,
|
|
||||||
}),
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
const awaitedTankopedia = await tankopedia;
|
|
||||||
const awaitedTankAverages = await tankAverages;
|
|
||||||
const careerWN8 =
|
|
||||||
careerRaw[id].reduce(
|
|
||||||
(accumulator, { tank_id, all }) =>
|
|
||||||
accumulator +
|
|
||||||
(awaitedTankAverages[tank_id] && all.battles > 0
|
|
||||||
? all.battles *
|
|
||||||
calculateWN8(awaitedTankAverages[tank_id].all, all)
|
|
||||||
: 0),
|
|
||||||
0,
|
|
||||||
) /
|
|
||||||
careerRaw[id].reduce(
|
|
||||||
(accumulator, { tank_id, all }) =>
|
|
||||||
accumulator +
|
|
||||||
(awaitedTankAverages[tank_id] && all.battles > 0 ? all.battles : 0),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
setDiff({
|
|
||||||
careerWN8,
|
|
||||||
|
|
||||||
list: (
|
|
||||||
Object.values(
|
|
||||||
diffNormalizedTankStats(session.tankStats, career),
|
|
||||||
) as IndividualTankStats[]
|
|
||||||
).map((stats) => {
|
|
||||||
return {
|
|
||||||
stats,
|
|
||||||
tankopedia: awaitedTankopedia[stats.tank_id],
|
|
||||||
career: career[stats.tank_id],
|
|
||||||
currentWN8: awaitedTankAverages[stats.tank_id]
|
|
||||||
? calculateWN8(awaitedTankAverages[stats.tank_id].all, stats.all)
|
|
||||||
: undefined,
|
|
||||||
careerWN8: awaitedTankAverages[stats.tank_id]
|
|
||||||
? calculateWN8(
|
|
||||||
awaitedTankAverages[stats.tank_id].all,
|
|
||||||
career[stats.tank_id].all,
|
|
||||||
)
|
|
||||||
: undefined,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async function setSession(region: Region, id: number, nickname: string) {
|
async function setSession(region: Region, id: number, nickname: string) {
|
||||||
input.current!.value = nickname;
|
input.current!.value = nickname;
|
||||||
|
|
||||||
@@ -148,17 +90,84 @@ export default function Page() {
|
|||||||
region,
|
region,
|
||||||
nickname,
|
nickname,
|
||||||
tankStats,
|
tankStats,
|
||||||
|
time: Date.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
recalculateDiff();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
async function recalculateDiff() {
|
||||||
|
// const session = useSession.getState();
|
||||||
|
|
||||||
|
if (session.isTracking) {
|
||||||
|
const { id, region } = session;
|
||||||
|
const careerRaw = await getWargamingResponse<TanksStats>(
|
||||||
|
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
|
);
|
||||||
|
const career = careerRaw[id].reduce<
|
||||||
|
Record<number, IndividualTankStats>
|
||||||
|
>(
|
||||||
|
(accumulator, curr) => ({
|
||||||
|
...accumulator,
|
||||||
|
[curr.tank_id]: curr,
|
||||||
|
}),
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
const awaitedTankopedia = await tankopedia;
|
||||||
|
const awaitedTankAverages = await tankAverages;
|
||||||
|
const careerWN8 =
|
||||||
|
careerRaw[id].reduce(
|
||||||
|
(accumulator, { tank_id, all }) =>
|
||||||
|
accumulator +
|
||||||
|
(awaitedTankAverages[tank_id] && all.battles > 0
|
||||||
|
? all.battles *
|
||||||
|
calculateWN8(awaitedTankAverages[tank_id].all, all)
|
||||||
|
: 0),
|
||||||
|
0,
|
||||||
|
) /
|
||||||
|
careerRaw[id].reduce(
|
||||||
|
(accumulator, { tank_id, all }) =>
|
||||||
|
accumulator +
|
||||||
|
(awaitedTankAverages[tank_id] && all.battles > 0
|
||||||
|
? all.battles
|
||||||
|
: 0),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
setDiff({
|
||||||
|
careerWN8,
|
||||||
|
|
||||||
|
list: (
|
||||||
|
Object.values(
|
||||||
|
diffNormalizedTankStats(session.tankStats, career),
|
||||||
|
) as IndividualTankStats[]
|
||||||
|
).map((stats) => {
|
||||||
|
return {
|
||||||
|
stats,
|
||||||
|
tankopedia: awaitedTankopedia[stats.tank_id],
|
||||||
|
career: career[stats.tank_id],
|
||||||
|
currentWN8: awaitedTankAverages[stats.tank_id]
|
||||||
|
? calculateWN8(
|
||||||
|
awaitedTankAverages[stats.tank_id].all,
|
||||||
|
stats.all,
|
||||||
|
)
|
||||||
|
: undefined,
|
||||||
|
careerWN8: awaitedTankAverages[stats.tank_id]
|
||||||
|
? calculateWN8(
|
||||||
|
awaitedTankAverages[stats.tank_id].all,
|
||||||
|
career[stats.tank_id].all,
|
||||||
|
)
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
recalculateDiff();
|
recalculateDiff();
|
||||||
const interval = setInterval(recalculateDiff, 1000 / REFRESH_RATE);
|
const interval = setInterval(recalculateDiff, 1000 / REFRESH_RATE);
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, []);
|
}, [session]);
|
||||||
|
|
||||||
const battles = diff?.list.reduce(
|
const battles = diff?.list.reduce(
|
||||||
(accumulator, { stats }) => accumulator + stats.all.battles,
|
(accumulator, { stats }) => accumulator + stats.all.battles,
|
||||||
@@ -345,7 +354,9 @@ export default function Page() {
|
|||||||
current: battlesWithWN8
|
current: battlesWithWN8
|
||||||
? Math.round(currentWN8).toLocaleString()
|
? Math.round(currentWN8).toLocaleString()
|
||||||
: '--',
|
: '--',
|
||||||
percentile: getWN8Percentile(currentWN8),
|
percentile: battlesWithWN8
|
||||||
|
? getWN8Percentile(currentWN8)
|
||||||
|
: undefined,
|
||||||
career: Math.round(diff.careerWN8).toLocaleString(),
|
career: Math.round(diff.careerWN8).toLocaleString(),
|
||||||
};
|
};
|
||||||
})(),
|
})(),
|
||||||
|
|||||||
Reference in new issue
Block a user