From 3c47dcbf913c91915afec6bd21547fed62d8d4cc Mon Sep 17 00:00:00 2001 From: juhitiwari Date: Fri, 18 Dec 2020 17:10:31 +0530 Subject: [PATCH 1/2] Find attempted questions by difficulty --- src/components/Table/index.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/components/Table/index.js b/src/components/Table/index.js index c4d4db7b..4e63b6cd 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -5,6 +5,7 @@ import { Row, Badge, NavLink, + Col, } from 'reactstrap'; import Toggle from 'react-toggle'; import ReactTooltip from 'react-tooltip'; @@ -39,6 +40,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 +66,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 +94,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]); }} /> From f61a68774d6ad586356872ca7c8521a459a62154 Mon Sep 17 00:00:00 2001 From: juhitiwari Date: Fri, 18 Dec 2020 17:25:39 +0530 Subject: [PATCH 2/2] removed unused import statement --- src/components/Table/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Table/index.js b/src/components/Table/index.js index 4e63b6cd..cb1ac4c5 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -5,7 +5,6 @@ import { Row, Badge, NavLink, - Col, } from 'reactstrap'; import Toggle from 'react-toggle'; import ReactTooltip from 'react-tooltip';