Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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(
() => ({
Expand All @@ -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]);
}}
/>
Expand Down