From 64bcc932d73e48fc512d86c1d9c1eb2b95e4366d Mon Sep 17 00:00:00 2001 From: Alexander Polynomdivision Date: Sun, 30 Sep 2018 14:46:32 +0200 Subject: [PATCH] fix: Metadata only updated on correct answers --- frontend/src/components/app.tsx | 5 +++++ frontend/src/containers/Application.ts | 5 ++++- frontend/src/pages/level.tsx | 2 -- frontend/src/pages/review.tsx | 31 +++++++++++++++----------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/app.tsx b/frontend/src/components/app.tsx index b93bf91..4dfecb3 100644 --- a/frontend/src/components/app.tsx +++ b/frontend/src/components/app.tsx @@ -31,6 +31,7 @@ interface IProps { setAuthenticated: (status: boolean) => void; setDidLogin: (status: boolean) => void; setUser: (user: IUser) => void; + setLastReview: (meta: IReviewMetadata) => void; }; // TODO: Replace the sessionStorage with localStorage? @@ -106,6 +107,10 @@ export default class Application extends React.Component { } setLastReview = (meta: IReviewMetadata) => { + // Update the state + this.props.setLastReview(meta); + + // Tell the server about the last review fetch(`${BACKEND_URL}/api/user/lastReview`, { headers: new Headers({ "Content-Type": "application/json", diff --git a/frontend/src/containers/Application.ts b/frontend/src/containers/Application.ts index bf14a1c..9382e0c 100644 --- a/frontend/src/containers/Application.ts +++ b/frontend/src/containers/Application.ts @@ -4,7 +4,9 @@ import { IUser } from "../models/user"; import Application from "../components/app"; -import { setAuthenticated, setUser, setDidLogin } from "../actions"; +import { setAuthenticated, setUser, setDidLogin, setLastReview } from "../actions"; + +import { IReviewMetadata } from "../models/review"; const mapStateToProps = state => { return { @@ -17,6 +19,7 @@ const mapDispatchToProps = dispatch => { setAuthenticated: (status: boolean) => dispatch(setAuthenticated(status)), setDidLogin: (state: boolean) => dispatch(setDidLogin(state)), setUser: (user: IUser) => dispatch(setUser(user)), + setLastReview: (meta: IReviewMetadata) => dispatch(setLastReview(meta)), }; }; diff --git a/frontend/src/pages/level.tsx b/frontend/src/pages/level.tsx index f85f94b..218acdd 100644 --- a/frontend/src/pages/level.tsx +++ b/frontend/src/pages/level.tsx @@ -89,8 +89,6 @@ const LevelPageWithRouter = withRouter( toReview = () => { const { vocab, lookedAt, id } = this.props; - console.log(this.props); - // Only go to the review if all vocabulary item have been looked at if (vocab.length === lookedAt.length) { this.props.updateDoneLevels(id); diff --git a/frontend/src/pages/review.tsx b/frontend/src/pages/review.tsx index 1ae85ee..d6cc8ec 100644 --- a/frontend/src/pages/review.tsx +++ b/frontend/src/pages/review.tsx @@ -41,6 +41,7 @@ interface IProps { loading: boolean; vocab: IVocab[]; current: IReviewCard; + metadata: IReviewMetadata; popoverOpen: boolean; popoverText: string; popoverColor: string; @@ -62,7 +63,7 @@ const ReviewPageWithRouter = withRouter( // Used for positioning the popover private buttonRef: HTMLButtonElement; private inputRef: HTMLInputElement; - private metadata: IReviewMetadata = { correct: 0, wrong: 0 }; + private sm2_metadata: any = {}; constructor(props: any) { super(props); @@ -120,7 +121,7 @@ const ReviewPageWithRouter = withRouter( } increaseMeta = (correct: number, wrong: number): IReviewMetadata => { - const { metadata } = this; + const { metadata } = this.props; return { wrong: metadata.wrong + wrong, @@ -148,13 +149,15 @@ const ReviewPageWithRouter = withRouter( // TODO: Show it's correct? // Show the next vocab word if (this.reviewQueue.size() === 0) { - // Go to the summary screen - this.props.setLastReview(this.metadata); + // Update the metadata + this.props.setReview(this.props.current, this.increaseMeta(1, 0)); + this.props.setLastReview(this.props.metadata); this.props.setLoading(true); // Show the drawer button again this.props.drawerButtonState(true); + // Go to the summary screen this.props.history.push("/review/summary"); } else { // Increase the vocab @@ -165,15 +168,17 @@ const ReviewPageWithRouter = withRouter( this.props.setPopover(true, "Das war fast richtig", "yellow", "black"); } else { // Find the IVocab item - const vocab = this.vocabFromId(this.props.current.id); - if (vocab) { - // Re-Add the vocabulary item to the review queue - // TODO: Only re-add when it when it's not re-queued - // vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue); - } else { - console.log("[ReviewPage::checkInput] Could not find IVocab item for wrong IReviewCard"); - } - + /* const vocab = this.vocabFromId(this.props.current.id); + * if (vocab) { + * // Re-Add the vocabulary item to the review queue + * // TODO: Only re-add when it when it's not re-queued + * // vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue); + * } else { + * console.log("[ReviewPage::checkInput] Could not find IVocab item for wrong IReviewCard"); + * } + */ + // Update the metadata + this.props.setReview(this.props.current, this.increaseMeta(0, 1)); this.props.setPopover(true, "Das war nicht richtig", "red", "white"); }