fix: Metadata only updated on correct answers
This commit is contained in:
parent
2276dad7a7
commit
64bcc932d7
@ -31,6 +31,7 @@ interface IProps {
|
|||||||
setAuthenticated: (status: boolean) => void;
|
setAuthenticated: (status: boolean) => void;
|
||||||
setDidLogin: (status: boolean) => void;
|
setDidLogin: (status: boolean) => void;
|
||||||
setUser: (user: IUser) => void;
|
setUser: (user: IUser) => void;
|
||||||
|
setLastReview: (meta: IReviewMetadata) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Replace the sessionStorage with localStorage?
|
// TODO: Replace the sessionStorage with localStorage?
|
||||||
@ -106,6 +107,10 @@ export default class Application extends React.Component<IProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLastReview = (meta: IReviewMetadata) => {
|
setLastReview = (meta: IReviewMetadata) => {
|
||||||
|
// Update the state
|
||||||
|
this.props.setLastReview(meta);
|
||||||
|
|
||||||
|
// Tell the server about the last review
|
||||||
fetch(`${BACKEND_URL}/api/user/lastReview`, {
|
fetch(`${BACKEND_URL}/api/user/lastReview`, {
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -4,7 +4,9 @@ import { IUser } from "../models/user";
|
|||||||
|
|
||||||
import Application from "../components/app";
|
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 => {
|
const mapStateToProps = state => {
|
||||||
return {
|
return {
|
||||||
@ -17,6 +19,7 @@ const mapDispatchToProps = dispatch => {
|
|||||||
setAuthenticated: (status: boolean) => dispatch(setAuthenticated(status)),
|
setAuthenticated: (status: boolean) => dispatch(setAuthenticated(status)),
|
||||||
setDidLogin: (state: boolean) => dispatch(setDidLogin(state)),
|
setDidLogin: (state: boolean) => dispatch(setDidLogin(state)),
|
||||||
setUser: (user: IUser) => dispatch(setUser(user)),
|
setUser: (user: IUser) => dispatch(setUser(user)),
|
||||||
|
setLastReview: (meta: IReviewMetadata) => dispatch(setLastReview(meta)),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,8 +89,6 @@ const LevelPageWithRouter = withRouter(
|
|||||||
toReview = () => {
|
toReview = () => {
|
||||||
const { vocab, lookedAt, id } = this.props;
|
const { vocab, lookedAt, id } = this.props;
|
||||||
|
|
||||||
console.log(this.props);
|
|
||||||
|
|
||||||
// Only go to the review if all vocabulary item have been looked at
|
// Only go to the review if all vocabulary item have been looked at
|
||||||
if (vocab.length === lookedAt.length) {
|
if (vocab.length === lookedAt.length) {
|
||||||
this.props.updateDoneLevels(id);
|
this.props.updateDoneLevels(id);
|
||||||
|
@ -41,6 +41,7 @@ interface IProps {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
vocab: IVocab[];
|
vocab: IVocab[];
|
||||||
current: IReviewCard;
|
current: IReviewCard;
|
||||||
|
metadata: IReviewMetadata;
|
||||||
popoverOpen: boolean;
|
popoverOpen: boolean;
|
||||||
popoverText: string;
|
popoverText: string;
|
||||||
popoverColor: string;
|
popoverColor: string;
|
||||||
@ -62,7 +63,7 @@ const ReviewPageWithRouter = withRouter(
|
|||||||
// Used for positioning the popover
|
// Used for positioning the popover
|
||||||
private buttonRef: HTMLButtonElement;
|
private buttonRef: HTMLButtonElement;
|
||||||
private inputRef: HTMLInputElement;
|
private inputRef: HTMLInputElement;
|
||||||
private metadata: IReviewMetadata = { correct: 0, wrong: 0 };
|
private sm2_metadata: any = {};
|
||||||
|
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -120,7 +121,7 @@ const ReviewPageWithRouter = withRouter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
increaseMeta = (correct: number, wrong: number): IReviewMetadata => {
|
increaseMeta = (correct: number, wrong: number): IReviewMetadata => {
|
||||||
const { metadata } = this;
|
const { metadata } = this.props;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
wrong: metadata.wrong + wrong,
|
wrong: metadata.wrong + wrong,
|
||||||
@ -148,13 +149,15 @@ const ReviewPageWithRouter = withRouter(
|
|||||||
// TODO: Show it's correct?
|
// TODO: Show it's correct?
|
||||||
// Show the next vocab word
|
// Show the next vocab word
|
||||||
if (this.reviewQueue.size() === 0) {
|
if (this.reviewQueue.size() === 0) {
|
||||||
// Go to the summary screen
|
// Update the metadata
|
||||||
this.props.setLastReview(this.metadata);
|
this.props.setReview(this.props.current, this.increaseMeta(1, 0));
|
||||||
|
this.props.setLastReview(this.props.metadata);
|
||||||
this.props.setLoading(true);
|
this.props.setLoading(true);
|
||||||
|
|
||||||
// Show the drawer button again
|
// Show the drawer button again
|
||||||
this.props.drawerButtonState(true);
|
this.props.drawerButtonState(true);
|
||||||
|
|
||||||
|
// Go to the summary screen
|
||||||
this.props.history.push("/review/summary");
|
this.props.history.push("/review/summary");
|
||||||
} else {
|
} else {
|
||||||
// Increase the vocab
|
// Increase the vocab
|
||||||
@ -165,15 +168,17 @@ const ReviewPageWithRouter = withRouter(
|
|||||||
this.props.setPopover(true, "Das war fast richtig", "yellow", "black");
|
this.props.setPopover(true, "Das war fast richtig", "yellow", "black");
|
||||||
} else {
|
} else {
|
||||||
// Find the IVocab item
|
// Find the IVocab item
|
||||||
const vocab = this.vocabFromId(this.props.current.id);
|
/* const vocab = this.vocabFromId(this.props.current.id);
|
||||||
if (vocab) {
|
* if (vocab) {
|
||||||
// Re-Add the vocabulary item to the review queue
|
* // Re-Add the vocabulary item to the review queue
|
||||||
// TODO: Only re-add when it when it's not re-queued
|
* // TODO: Only re-add when it when it's not re-queued
|
||||||
// vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue);
|
* // vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue);
|
||||||
} else {
|
* } else {
|
||||||
console.log("[ReviewPage::checkInput] Could not find IVocab item for wrong IReviewCard");
|
* 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");
|
this.props.setPopover(true, "Das war nicht richtig", "red", "white");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user