@@ -39,6 +39,17 @@ const Table = () => {
3939 checkedList = newCheckedList ;
4040 window . localStorage . setItem ( 'checked' , JSON . stringify ( checkedList ) ) ;
4141 }
42+ const data = React . useMemo ( ( ) => questions , [ ] ) ;
43+ /* Get a list of all checked questions in the form of a dictionary keys as question difficulty */
44+ const checkedQuestionsByDifficulty = { Easy : 0 , Hard : 0 , Medium : 0 } ;
45+ for ( let i = 0 ; i < checkedList . length ; i += 1 ) {
46+ if ( checkedList [ i ] ) {
47+ checkedQuestionsByDifficulty [ data [ i ] . difficulty ] += 1 ;
48+ }
49+ }
50+ const [ checkQuestionsDict , setcheckQuestionsDict ] = useState (
51+ checkedQuestionsByDifficulty ,
52+ ) ;
4253
4354 const [ checked , setChecked ] = useState ( checkedList ) ;
4455
@@ -54,7 +65,8 @@ const Table = () => {
5465 window . localStorage . setItem ( 'showPatterns' , JSON . stringify ( showPatterns ) ) ;
5566 } , [ showPatterns ] ) ;
5667
57- const data = React . useMemo ( ( ) => questions , [ ] ) ;
68+ /*To view the number of question solved by difficulty*/
69+ console . log ( checkQuestionsDict ) ;
5870
5971 const defaultColumn = React . useMemo (
6072 ( ) => ( {
@@ -81,6 +93,22 @@ const Table = () => {
8193 checked [ cellInfo . row . original . id ] = ! checked [
8294 cellInfo . row . original . id
8395 ] ;
96+ /*increment or decrement question count for the correct difficulty from the checkbox */
97+ if ( checked [ cellInfo . row . original . id ] ) {
98+ setcheckQuestionsDict ( prevState => ( {
99+ ...prevState ,
100+ [ cellInfo . row . original . difficulty ] :
101+ prevState [ cellInfo . row . original . difficulty ] + 1 ,
102+ } ) ) ;
103+ } else {
104+ setcheckQuestionsDict ( prevState => ( {
105+ ...prevState ,
106+ [ cellInfo . row . original . difficulty ] :
107+ prevState [ cellInfo . row . original . difficulty ] === 0
108+ ? 0
109+ : prevState [ cellInfo . row . original . difficulty ] - 1 ,
110+ } ) ) ;
111+ }
84112 setChecked ( [ ...checked ] ) ;
85113 } }
86114 />
0 commit comments