diff --git a/src/components/revise/Revise.module.scss b/src/components/revise/Revise.module.scss index 5e5297a..0003c42 100644 --- a/src/components/revise/Revise.module.scss +++ b/src/components/revise/Revise.module.scss @@ -12,7 +12,7 @@ font-size: 1.2rem; font-weight: 700; color: white; - background-color: var(--teal); + background-color: var(--red); margin: 0 auto; display: block; border: none; diff --git a/src/components/revise/Revise.tsx b/src/components/revise/Revise.tsx index 76bc49e..792cf1b 100644 --- a/src/components/revise/Revise.tsx +++ b/src/components/revise/Revise.tsx @@ -3,33 +3,100 @@ import styles from './Revise.module.scss'; import { Question } from "./question/Question"; import { Summary } from "./summary/Summary"; -import { recollectionQuestions } from "../../services/recollectionquestions"; -import { MongoShelfWord } from "../../shared/models/shelf"; - - -interface WordWithShelfId extends MongoShelfWord { - shelfId: string -} +import { recollectionQuestions, updateRecollectionQuestion } from "../../services/recollectionquestions"; +import { MobileShelf } from "../../shared/models/shelf"; +import { MobileUser } from "../../shared/models/user"; export const Revise: React.FC = () => { const [progressState, setProgressState] = useState<'INTRO' | 'QUESTION' | 'END'>('QUESTION'); - const [questions, setQuestions] = useState>([]); + const [questions, setQuestions] = useState>([]); + const [answeredQuestions, setAnsweredQuestion] = useState>([]); + + const [currentQuestion, setCurrentQuestion] = useState(0); useEffect(() => { recollectionQuestions().then((response: any) => { - setQuestions(response.data); + let questions: Array = response.data; + const curatedQuestions: Array = []; + let allShelves: Array = []; + + const userProfile: MobileUser = JSON.parse(localStorage.getItem('userProfile') || ""); + + userProfile.categories.forEach(category => { + category.shelves?.forEach((shelf) => { + allShelves.push(shelf); + }); + }); + + questions.forEach((question) => { + let index = allShelves.findIndex(shelf => shelf._id === question.shelfId); + + if (index !== undefined) { + const word = allShelves[index].words?.find(word => word.word._id === question.word)?.word; + + if (word !== undefined) { + curatedQuestions.push({ + ...question, + word: word + }) + } + + } + + }); + + setQuestions(curatedQuestions); + + if (curatedQuestions.length === 0) { + setProgressState('END'); + } + }, (e) => { window.alert("Failed to get questions"); console.log(e); }); }, []); + + return
{ progressState === 'QUESTION' &&
- + + { questions.map((question, index) => { + return currentQuestion === index && { + let temp = answeredQuestions; + + temp.push({ + wordId: question.word._id, + hasRecalled: flag, + }); + + setAnsweredQuestion(temp); + + console.log(question) + + setTimeout(() => { + + if (currentQuestion < questions.length - 1) { + setCurrentQuestion(currentQuestion + 1); + } else { + setProgressState('END'); + } + + updateRecollectionQuestion(question.shelfId, question.word._id, flag); + + }, 200); + + }} /> + }) }
} diff --git a/src/components/revise/options/Options.module.scss b/src/components/revise/options/Options.module.scss index 8f6ebc0..305f84c 100644 --- a/src/components/revise/options/Options.module.scss +++ b/src/components/revise/options/Options.module.scss @@ -33,7 +33,7 @@ p { font-size: 1.2rem; font-weight: 500; - color: var(--black); + color: var(--grey); } .checkmark { diff --git a/src/components/revise/options/Options.tsx b/src/components/revise/options/Options.tsx index 893a4fc..06292cb 100644 --- a/src/components/revise/options/Options.tsx +++ b/src/components/revise/options/Options.tsx @@ -1,43 +1,33 @@ -import React from "react"; +import React, { useState } from "react"; import styles from './Options.module.scss'; import { ReactComponent as CheckCircleIcon } from '../../../assets/icons/check.svg'; -export const Options: React.FC = () => { - return
    -
  • -

    - Argentina & Leo Messi -

    -
    - -
    -
  • - -
  • -

    - Brazil & Neymar -

    -
    - -
    -
  • +type OwnProps = { + options: Array<{ + text: string, + function:() => void, + }> +} -
  • -

    - Chile & Sanchez -

    -
    - -
    -
  • +export const Options: React.FC = (props) => { + const [selectedOption, setSelectedOption] = useState<{ + text: string, + function:() => void, + } | undefined>(); -
  • -

    - Mexico & Chicharito -

    -
    - -
    -
  • -
; + return
    + { props.options.map((option, index) => { + return
  • { + option.function(); + setSelectedOption(option); + }}> +

    + { option.text } +

    + { selectedOption === option &&
    + +
    } +
  • + }) } +
; } \ No newline at end of file diff --git a/src/components/revise/question/Question.module.scss b/src/components/revise/question/Question.module.scss index dd409ad..e6de76c 100644 --- a/src/components/revise/question/Question.module.scss +++ b/src/components/revise/question/Question.module.scss @@ -1,7 +1,7 @@ $common-width: calc(100% - 4rem); .questionHolder { - height: calc(100vh - 8rem); + height: calc(100vh - 6rem); padding-top: 2rem; overflow: auto; } @@ -76,4 +76,52 @@ $common-width: calc(100% - 4rem); .answerTypes { width: #{$common-width}; margin: 0 auto 2rem; +} + +.meaning { + width: $common-width; + margin: 0 auto 2rem; + list-style: none; + position: relative; + + &::before { + content: ''; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: var(--lighter-grey); + position: absolute; + border-radius: 5px; + opacity: 0.95; + transition: opacity 0.5s; + } + + &.unblock { + &::before { + opacity: 0; + } + } + + li { + margin-bottom: 1rem; + + } + + p { + font-size: 14px; + color: var(--light-grey); + + span { + vertical-align: middle; + } + } +} + +.caption { + font-size: 14px; + color: var(--light-grey); + font-style: italic; + width: $common-width; + margin: 0 auto 2rem; } \ No newline at end of file diff --git a/src/components/revise/question/Question.tsx b/src/components/revise/question/Question.tsx index a4a8ec4..1dfef8e 100644 --- a/src/components/revise/question/Question.tsx +++ b/src/components/revise/question/Question.tsx @@ -1,22 +1,48 @@ -import React from "react"; +import React, { useState } from "react"; import styles from './Question.module.scss'; -import { ReactComponent as TimeIcon } from '../../../assets/icons/timer.svg'; import { Options } from "../options/Options"; +import { Word } from "../../../shared/models/word"; + +type OwnProps = { + questionNumber: number, + totalQuestions: number, + word: Word, + selectOption: (hasRecalled: boolean) => void, +} + +export const Question: React.FC = (props) => { + const [isMeaningShown, setShowMeaning] = useState(false); -export const Question: React.FC = () => { return
- - 30 - + + {/* 30 + */}
-

Question 10/10

+

Question {props.questionNumber + 1} / { props.totalQuestions }

+ +

Do you recall this word?
{ props.word.name }

+ +
    setShowMeaning(true)}> + { props.word.grammaticalDetails.map((detail, index) => { + return
  1. +

    - { detail.description }

    +
  2. + }) } +
-

Who won Copa America 2021 and who was the Captian?

+ { !isMeaningShown &&

Tap on the blocked section to see the meaning

}
- + props.selectOption(true) + }, { + text: 'No', + function: () => props.selectOption(false) + }]} />
} \ No newline at end of file