Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
fix: fix empty page after reviewing last sentence (fixes #498)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler committed Oct 28, 2021
1 parent 2114b38 commit 728f429
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions web/src/components/review-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export default function SwipeReview(props: Props) {
[]
);

if (sentences.length === 0) {
return null;
}

const APPROVAL_DIRECTIONS: Record<string, boolean> = {
left: false,
right: true,
Expand Down Expand Up @@ -102,9 +98,16 @@ export default function SwipeReview(props: Props) {
direction = 'up';
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await cardsRefs[currentSentenceIndex].current.swipe(direction);
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await cardsRefs[currentSentenceIndex].current.swipe(direction);
} catch (error) {
// If the swipe failed we either could not process the swipe at all
// or it was the last card leading to an error on the card as the
// component gets unmounted at the same time due to no sentences
// being left to review. In both cases we can ignore this error.
}
};

useEffect(() => {
Expand All @@ -128,11 +131,15 @@ export default function SwipeReview(props: Props) {
}, [currentSentenceIndex]);

useEffect(() => {
if (reviewedSentencesCount + skippedSentencesCount === sentences.length) {
if (sentences.length !== 0 && reviewedSentencesCount + skippedSentencesCount === sentences.length) {
submitSentences();
}
}, [reviewedSentencesCount, skippedSentencesCount]);

if (sentences.length === 0) {
return null;
}

return (
<form id="review-form" onSubmit={onSubmit}>
<Prompt
Expand Down

0 comments on commit 728f429

Please sign in to comment.