Skip to content

Commit

Permalink
Ensure that current screenshot is always set and is not undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
krasun committed Nov 4, 2024
1 parent 6ffed16 commit 453251f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function Game({
return;
}

if (currentIndex === screenshots.length - 1) {
if (currentIndex >= screenshots.length - 1) {
setProcessing(true);

const response = await fetch(`/game/${sessionKey}/end`, {
Expand All @@ -126,7 +126,7 @@ export default function Game({
return;
}

setCurrentIndex((currentIndex) => currentIndex + 1);
setCurrentIndex((currentIndex) => Math.min(currentIndex + 1, screenshots.length - 1));
setCurrentRoundStartedAt(new Date());
const updatedResponses = [
...responses,
Expand Down Expand Up @@ -167,10 +167,10 @@ export default function Game({
(currentIndex / screenshots.length) * 100
);
const [currentScreenshot, setCurrentScreenshot] = useState<Screenshot>(
screenshots[currentIndex]
screenshots[Math.min(currentIndex, screenshots.length - 1)]
);
useEffect(() => {
setCurrentScreenshot(screenshots[currentIndex]);
setCurrentScreenshot(screenshots[Math.min(currentIndex, screenshots.length - 1)]);
setProgress((currentIndex / screenshots.length) * 100);
}, [currentIndex, screenshots]);

Expand Down

0 comments on commit 453251f

Please sign in to comment.