diff --git a/src/components/Table/index.js b/src/components/Table/index.js index c4d4db7b..cb1ac4c5 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -39,6 +39,17 @@ const Table = () => { checkedList = newCheckedList; window.localStorage.setItem('checked', JSON.stringify(checkedList)); } + const data = React.useMemo(() => questions, []); + /* Get a list of all checked questions in the form of a dictionary keys as question difficulty */ + const checkedQuestionsByDifficulty = { Easy: 0, Hard: 0, Medium: 0 }; + for (let i = 0; i < checkedList.length; i += 1) { + if (checkedList[i]) { + checkedQuestionsByDifficulty[data[i].difficulty] += 1; + } + } + const [checkQuestionsDict, setcheckQuestionsDict] = useState( + checkedQuestionsByDifficulty, + ); const [checked, setChecked] = useState(checkedList); @@ -54,7 +65,8 @@ const Table = () => { window.localStorage.setItem('showPatterns', JSON.stringify(showPatterns)); }, [showPatterns]); - const data = React.useMemo(() => questions, []); + /*To view the number of question solved by difficulty*/ + console.log(checkQuestionsDict); const defaultColumn = React.useMemo( () => ({ @@ -81,6 +93,22 @@ const Table = () => { checked[cellInfo.row.original.id] = !checked[ cellInfo.row.original.id ]; + /*increment or decrement question count for the correct difficulty from the checkbox */ + if (checked[cellInfo.row.original.id]) { + setcheckQuestionsDict(prevState => ({ + ...prevState, + [cellInfo.row.original.difficulty]: + prevState[cellInfo.row.original.difficulty] + 1, + })); + } else { + setcheckQuestionsDict(prevState => ({ + ...prevState, + [cellInfo.row.original.difficulty]: + prevState[cellInfo.row.original.difficulty] === 0 + ? 0 + : prevState[cellInfo.row.original.difficulty] - 1, + })); + } setChecked([...checked]); }} />