fix: Metadata only updated on correct answers

This commit is contained in:
Alexander Polynomdivision 2018-09-30 14:46:32 +02:00
parent 2276dad7a7
commit 64bcc932d7
4 changed files with 27 additions and 16 deletions

View File

@ -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<IProps> {
}
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",

View File

@ -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)),
};
};

View File

@ -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);

View File

@ -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");
}