feat: Only mark a level as done when the review is completed

This commit is contained in:
Alexander Polynomdivision 2018-10-03 14:19:23 +02:00
parent b32603f213
commit 5b399bf0d2
3 changed files with 12 additions and 3 deletions

View File

@ -346,7 +346,6 @@ export default class Application extends React.Component<IProps> {
return <LevelPage
id={match.params.id}
levelVocab={this.getLevelVocab}
updateDoneLevels={this.updateDoneLevels}
setLastReview={this.setLastReview} />;
} else {
return <Redirect to="/login" />;
@ -358,6 +357,7 @@ export default class Application extends React.Component<IProps> {
if (this.isAuthenticated()) {
return <ReviewPage
reviewType={ReviewType.LEVEL}
updateDoneLevels={this.updateDoneLevels}
levelId={match.params.id}
vocabByLevel={this.getLevelVocab}
setLastReview={this.setLastReview} />;

View File

@ -19,7 +19,6 @@ import { IVocab, VocabType } from "../models/vocab";
interface IProps {
id: string;
levelVocab: (id: string) => Promise<IVocab[]>;
updateDoneLevels: (id: string) => void;
history: any;
@ -93,7 +92,6 @@ const LevelPageWithRouter = withRouter(
// Only go to the review if all vocabulary item have been looked at
if (vocab.length === lookedAt.length) {
this.props.updateDoneLevels(id);
this.props.setLoading(true);
this.props.history.push(`/review/level/${id}`);
}

View File

@ -39,6 +39,7 @@ interface IProps {
levelId?: number;
vocabByLevel?: (level: number) => Promise<IVocab[]>;
vocabByQueue?: () => Promise<IVocab[]>;
updateDoneLevels?: (id: string) => void;
setLastReview: (meta: IReviewMetadata, sm2: any, delta: number) => void;
reviewType: ReviewType;
@ -222,6 +223,16 @@ const ReviewPageWithRouter = withRouter(
this.props.setLastReview(newMeta, this.sm2_metadata, this.score_delta);
this.props.setLoading(true);
// If we're reviewing a level, then that level should be
// marked as complete
if (this.props.reviewType === ReviewType.LEVEL) {
// NOTE: We can ensure that both updateDoneLevels and
// levelId are attributes of this.props, since
// reviewType === ReviewType.LEVEL requires those.
//@ts-ignore
this.props.updateDoneLevels(this.props.levelId);
}
// Show the drawer button again
this.props.drawerButtonState(true);