@@ -45,6 +45,10 @@ const Table = () => {
45
45
JSON . parse ( localStorage . getItem ( 'checked' ) ) ||
46
46
new Array ( questions . length ) . fill ( false ) ;
47
47
48
+ let checkedAtList =
49
+ JSON . parse ( localStorage . getItem ( 'checkedAt' ) ) ||
50
+ new Array ( questions . length ) . fill ( '' ) ;
51
+
48
52
/* If the user has previously visited the website, then an array in
49
53
LocalStorage would exist of a certain length which corresponds to which
50
54
questions they have/have not completed. In the event that we add new questions
@@ -62,6 +66,17 @@ const Table = () => {
62
66
window . localStorage . setItem ( 'checked' , JSON . stringify ( checkedList ) ) ;
63
67
}
64
68
69
+ if ( checkedAtList . length !== questions . length ) {
70
+ const resizedCheckedAtList = new Array ( questions . length ) . fill ( '' ) ;
71
+
72
+ for ( let i = 0 ; i < checkedAtList . length ; i += 1 ) {
73
+ resizedCheckedAtList [ i ] = checkedAtList [ i ] ;
74
+ }
75
+
76
+ checkedAtList = resizedCheckedAtList ;
77
+ window . localStorage . setItem ( 'checkedAt' , JSON . stringify ( checkedAtList ) ) ;
78
+ }
79
+
65
80
const filteredByCheckbox = ( ) => {
66
81
const checkbox = localStorage . getItem ( 'checkbox' ) || '' ;
67
82
return questions . filter ( question => {
@@ -91,6 +106,7 @@ const Table = () => {
91
106
totalDifficultyCount [ questions [ i ] . difficulty ] += 1 ;
92
107
}
93
108
109
+ const [ checkedAt , setCheckedAt ] = useState ( checkedAtList ) ;
94
110
const [ data , setData ] = useState ( filteredByCheckbox ( ) ) ;
95
111
const [ difficultyCount , setDifficultyCount ] = useState ( difficultyMap ) ;
96
112
const [ checked , setChecked ] = useState ( checkedList ) ;
@@ -102,6 +118,10 @@ const Table = () => {
102
118
window . localStorage . setItem ( 'checked' , JSON . stringify ( checked ) ) ;
103
119
} , [ checked ] ) ;
104
120
121
+ useEffect ( ( ) => {
122
+ window . localStorage . setItem ( 'checkedAt' , JSON . stringify ( checkedAt ) ) ;
123
+ } , [ checkedAt ] ) ;
124
+
105
125
useEffect ( ( ) => {
106
126
window . localStorage . setItem ( 'showPatterns' , JSON . stringify ( showPatterns ) ) ;
107
127
} , [ showPatterns ] ) ;
@@ -134,6 +154,8 @@ const Table = () => {
134
154
const [ resetModal , setResetModal ] = React . useState ( false ) ;
135
155
const toggleResetModal = ( ) => {
136
156
setResetModal ( ! resetModal ) ;
157
+ const clearedCheckedAt = checkedAt . map ( ( ) => null ) ;
158
+ setCheckedAt ( clearedCheckedAt ) ;
137
159
} ;
138
160
139
161
return (
@@ -200,6 +222,13 @@ const Table = () => {
200
222
checked [ cellInfo . row . original . id ] = ! checked [
201
223
cellInfo . row . original . id
202
224
] ;
225
+ const currentTime = new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
226
+ // const updatedCheckedAt = [...checkedAt];
227
+ checkedAt [ cellInfo . row . original . id ] = checked [
228
+ cellInfo . row . original . id
229
+ ]
230
+ ? currentTime
231
+ : null ;
203
232
const question = questions . find (
204
233
q => q . id === cellInfo . row . original . id ,
205
234
) ;
@@ -218,6 +247,7 @@ const Table = () => {
218
247
setDifficultyCount ( difficultyCount ) ;
219
248
setChecked ( [ ...checked ] ) ;
220
249
setData ( filteredByCheckbox ( ) ) ;
250
+ setCheckedAt ( [ ...checkedAt ] ) ;
221
251
} }
222
252
/>
223
253
</ span >
@@ -451,6 +481,19 @@ const Table = () => {
451
481
} ,
452
482
Filter : SelectColumnFilter ,
453
483
} ,
484
+ {
485
+ Header : 'Last Solved On' ,
486
+ accessor : 'LastSolvedOn' ,
487
+ disableSortBy : true ,
488
+ Cell : cellInfo => {
489
+ return (
490
+ < div className = "lastSolvedOn" >
491
+ { checkedAt [ cellInfo . row . original . id ] }
492
+ </ div >
493
+ ) ;
494
+ } ,
495
+ disableFilters : true ,
496
+ } ,
454
497
] ,
455
498
} ,
456
499
] ,
0 commit comments