Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrap up mode bug #47

Merged
merged 4 commits into from Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitpod.yml
@@ -0,0 +1,2 @@
tasks:
- before: npm i -g firebase-tools
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -2,6 +2,8 @@
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"start:tunnel": "expo start --tunnel",
"firelogin:tunnel": "firebase login --no-localhost",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
Expand Down Expand Up @@ -49,6 +51,7 @@
"babel-plugin-inline-dotenv": "^1.5.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-preset-expo": "~8.1.0",
"firebase-tools": "^8.4.3",
"fs-extra": "^9.0.0",
"jest-expo": "^37.0.0",
"pre-commit": "^1.2.2",
Expand Down
22 changes: 7 additions & 15 deletions src/features/reviews/useReviewSession.js
Expand Up @@ -108,6 +108,7 @@ export default (reviews, subjects) => {
}, [
completedCards,
completedReviews,
unfinishedReviews,
incorrectCards,
incorrectReviews,
]);
Expand Down Expand Up @@ -137,7 +138,8 @@ export default (reviews, subjects) => {
setUnfinishedReviews(newUnfinishedReviews)

// a card is surely complete when answered correctly
setCompletedCards(Object.assign({}, completedCards, { [id]: true }));
const newCompletedCards = Object.assign({}, completedCards, { [id]: true });
setCompletedCards(newCompletedCards);
}

if (!correct) {
Expand All @@ -152,12 +154,10 @@ export default (reviews, subjects) => {
if (isReviewCompleted) {

if (typeof onReviewComplete === 'function') {
const incorrectMeaningAnswers = incorrectMeanings[reviewId];
const incorrectReadingAnswers = incorrectReadings[reviewId];
onReviewComplete({
review,
incorrectMeanings: incorrectMeaningAnswers,
incorrectReadings: incorrectReadingAnswers,
incorrectMeanings: incorrectMeanings[reviewId],
incorrectReadings: incorrectReadings[reviewId],
})
}

Expand All @@ -172,17 +172,10 @@ export default (reviews, subjects) => {
// need to find the reviewed item in the queue

// find index of the removed item
const reviewedQueueItemIndex = queue.findIndex(i => (
const newQueue = queue.filter(i => !(
i.id === id &&
i.reviewType === reviewType
));

// this shouldn't happen
if (reviewedQueueItemIndex === -1) return;

// remove item from the the list
const newQueue = queue.slice();
newQueue.splice(reviewedQueueItemIndex, 1);

// if answer was incorrect, put the item back
// into the queue randomly
Expand All @@ -201,7 +194,7 @@ export default (reviews, subjects) => {
}

// set the new queue
setQueue(newQueue || []);
setQueue(newQueue);
}

return {
Expand All @@ -219,5 +212,4 @@ export default (reviews, subjects) => {
incorrectMeanings,
incorrectReadings,
}

}
2 changes: 2 additions & 0 deletions src/mock/freeAssignments.js
Expand Up @@ -55,6 +55,7 @@ export default [
"srs_stage": 8,
}
},
/*
{
"id": 8,
"data": {
Expand All @@ -79,4 +80,5 @@ export default [
"srs_stage": 4,
}
},
*/
];
29 changes: 14 additions & 15 deletions src/screens/Review/Review.js
@@ -1,4 +1,4 @@
import React, { useState, useMemo } from 'react';
import React, { useState, useEffect, useMemo } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import { StyleSheet, View, Text } from 'react-native';
Expand Down Expand Up @@ -50,7 +50,7 @@ const Review = ({ demo = false, stopDemo } = {}) => {

// manage review session
const {
queue: _queue,
queue,
submitAnswer,
subjectsDict,
totalCards,
Expand All @@ -61,19 +61,18 @@ const Review = ({ demo = false, stopDemo } = {}) => {
reviews,
subjects,
);
// process queue
const queue = useMemo(() => _queue
// wrap up mode filter
.filter(i => wrapUpMode ? _.get(unfinishedReviews, i.review.id) : true)
, [
_queue,

const queueFiltered = useMemo(() => (
queue
// wrap up mode filter
.filter(i => wrapUpMode ? !_.isNil(_.get(unfinishedReviews, i.review.id)) : true)
), [
queue,
wrapUpMode,
unfinishedReviews,
])

// are all queue items asked
const isQueueClear = !loadingReviews && queue.length === 0;
const isQueueClear = !loadingReviews && queueFiltered.length === 0;

return (
<>
Expand Down Expand Up @@ -122,15 +121,15 @@ const Review = ({ demo = false, stopDemo } = {}) => {
/>

{/* render deck */}
{queue.length > 0 && (
{queueFiltered.length > 0 && (
<Deck
style={styles.deck}
cards={queue}
cards={queueFiltered}
dismissCard={direction => {
submitAnswer(
// item that was submitted: the top item
// of the processed queue list
queue.slice(0, 1)[0],
queueFiltered[0],
// right direction means correct answer
direction === 'right',
// callback for when the submit answer causes
Expand Down Expand Up @@ -184,7 +183,7 @@ const Review = ({ demo = false, stopDemo } = {}) => {

return (
<Card
key={id}
key={`${id}_${reviewType}`}
deckProps={props}
subjectType={subjectType}
reviewType={reviewType}
Expand Down