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

Commit

Permalink
fix: fix empty page after reviewing last sentence (fixes common-voice…
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler authored and HarikalarKutusu committed Oct 28, 2021
1 parent 597769d commit f40827c
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 @@ -37,10 +37,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 @@ -104,9 +100,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 @@ -131,11 +134,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}>
<Localized id="sc-review-title" attrs={{ message: true }}>
Expand Down

0 comments on commit f40827c

Please sign in to comment.