Skip to content

Commit c8c2e9f

Browse files
committed
More robust pause handling
1 parent 3bb0463 commit c8c2e9f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

functions/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ export const finishGame = functions.https.onCall(async (data, context) => {
8080
);
8181
}
8282
const pause = gameData.child("pause").val();
83+
const pauseEnd = pause?.end ?? finalTime;
8384
const pauseTime =
8485
(pause?.previous ?? 0) +
85-
(pause?.start ? (pause.end ?? finalTime) - pause.start : 0);
86+
(pause?.start < pauseEnd ? pauseEnd - pause.start : 0);
8687

8788
// The game has ended, so we attempt to do an atomic update.
8889
// Safety: Events can only be appended to the game, so the final time must remain the same.

src/components/GameSidebar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ function GameSidebar({ game, scores, leaderboard, pause, endedAt }) {
5353
const { pathname } = useLocation();
5454
const time = useMoment(500);
5555
const gameTime = endedAt || time;
56+
const pauseEnd = pause?.end ?? gameTime;
5657
const pauseTime =
5758
(pause?.previous ?? 0) +
58-
(pause?.start ? (pause.end ?? gameTime) - pause.start : 0);
59+
(pause?.start < pauseEnd ? pauseEnd - pause.start : 0);
5960

6061
return (
6162
<Paper className={classes.sidebar}>

0 commit comments

Comments
 (0)