Skip to content

Commit

Permalink
fix crash on account with no perfs (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro authored Nov 11, 2023
1 parent f1896a7 commit d1752e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
56 changes: 29 additions & 27 deletions src/components/common/AccountCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ function AccountCards({
const account = session.lichess.account;
const lichessSession = session.lichess;
const totalGames =
(account.perfs.ultraBullet?.games ?? 0) +
(account.perfs.bullet?.games ?? 0) +
(account.perfs.blitz?.games ?? 0) +
(account.perfs.rapid?.games ?? 0) +
(account.perfs.classical?.games ?? 0);
(account.perfs?.ultraBullet?.games ?? 0) +
(account.perfs?.bullet?.games ?? 0) +
(account.perfs?.blitz?.games ?? 0) +
(account.perfs?.rapid?.games ?? 0) +
(account.perfs?.classical?.games ?? 0);

const stats = [];
const speeds = ["bullet", "blitz", "rapid", "classical"] as const;

for (const speed of speeds) {
const perf = account.perfs[speed];
if (perf) {
stats.push({
value: perf.rating,
label: speed,
diff: perf.prog,
});
if (account.perfs) {
for (const speed of speeds) {
const perf = account.perfs[speed];
if (perf) {
stats.push({
value: perf.rating,
label: speed,
diff: perf.prog,
});
}
}
}

Expand Down Expand Up @@ -69,13 +71,13 @@ function AccountCards({
sessions.map((s) =>
s.lichess?.account.id === account.id
? {
...s,
lichess: {
account: account,
accessToken: lichessSession.accessToken,
},
updatedAt: Date.now(),
}
...s,
lichess: {
account: account,
accessToken: lichessSession.accessToken,
},
updatedAt: Date.now(),
}
: s
)
);
Expand Down Expand Up @@ -120,13 +122,13 @@ function AccountCards({
sessions.map((s) =>
s.chessCom?.username === session.chessCom?.username
? {
...s,
chessCom: {
username: session.chessCom!.username,
stats,
},
updatedAt: Date.now(),
}
...s,
chessCom: {
username: session.chessCom!.username,
stats,
},
updatedAt: Date.now(),
}
: s
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/lichess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type LichessPerf = {
export type LichessAccount = {
id: string;
username: string;
perfs: {
perfs?: {
chess960?: LichessPerf;
atomic?: LichessPerf;
racingKings?: LichessPerf;
Expand Down

0 comments on commit d1752e5

Please sign in to comment.