@@ -19,6 +19,7 @@ import {
19
19
DefaultColumnFilter ,
20
20
SelectDifficultyColumnFilter ,
21
21
SelectColumnFilter ,
22
+ SelectCheckedColumnFilter ,
22
23
} from './filters' ;
23
24
import { Event } from '../Shared/Tracking' ;
24
25
@@ -31,20 +32,19 @@ import PatternFrequencies from '../PatternFrequencies';
31
32
const iconPath = `${ process . env . PUBLIC_URL } /assets/icons/` ;
32
33
33
34
const Table = ( ) => {
34
- const data = React . useMemo ( ( ) => questions , [ ] ) ;
35
35
const [ resetCount , setResetCount ] = useState ( 0 ) ;
36
36
let checkedList =
37
37
JSON . parse ( localStorage . getItem ( 'checked' ) ) ||
38
- new Array ( data . length ) . fill ( false ) ;
38
+ new Array ( questions . length ) . fill ( false ) ;
39
39
40
40
/* If the user has previously visited the website, then an array in
41
41
LocalStorage would exist of a certain length which corresponds to which
42
42
questions they have/have not completed. In the event that we add new questions
43
43
to the list, then we would need to resize and copy the existing 'checked'
44
44
array before updating it in LocalStorage in order to transfer their saved
45
45
progress. */
46
- if ( checkedList . length !== data . length ) {
47
- const resizedCheckedList = new Array ( data . length ) . fill ( false ) ;
46
+ if ( checkedList . length !== questions . length ) {
47
+ const resizedCheckedList = new Array ( questions . length ) . fill ( false ) ;
48
48
49
49
for ( let i = 0 ; i < checkedList . length ; i += 1 ) {
50
50
resizedCheckedList [ i ] = checkedList [ i ] ;
@@ -54,6 +54,24 @@ const Table = () => {
54
54
window . localStorage . setItem ( 'checked' , JSON . stringify ( checkedList ) ) ;
55
55
}
56
56
57
+ const filteredByCheckbox = ( ) => {
58
+ return questions . filter ( question => {
59
+ const checkbox = localStorage . getItem ( 'checkbox' ) || '' ;
60
+ if ( ! checkbox ) return true ;
61
+ return question . checkbox === checkbox ;
62
+ } ) ;
63
+ } ;
64
+
65
+ for ( let i = 0 ; i < questions . length ; i += 1 ) {
66
+ if ( checkedList [ questions [ i ] . id ] ) {
67
+ questions [ i ] . checkbox = 'Checked' ;
68
+ } else {
69
+ questions [ i ] . checkbox = 'Unchecked' ;
70
+ }
71
+ }
72
+
73
+ const [ data , setData ] = useState ( filteredByCheckbox ( ) ) ;
74
+
57
75
const difficultyMap = { Easy : 0 , Medium : 0 , Hard : 0 } ;
58
76
const totalDifficultyCount = { Easy : 0 , Medium : 0 , Hard : 0 } ;
59
77
for ( let i = 0 ; i < data . length ; i += 1 ) {
@@ -160,6 +178,8 @@ const Table = () => {
160
178
>
161
179
Reset
162
180
</ Button >
181
+ < br />
182
+ < br />
163
183
< Modal isOpen = { resetModal } toggle = { toggleResetModal } >
164
184
< ModalHeader toggle = { toggleResetModal } >
165
185
Are you sure you want to reset your progress?
@@ -174,7 +194,12 @@ const Table = () => {
174
194
</ span >
175
195
) ;
176
196
} ,
177
- id : 'Checkbox' ,
197
+ accessor : 'checkbox' ,
198
+ id : 'checkbox' ,
199
+ filterByCheckbox : ( ) => {
200
+ setData ( filteredByCheckbox ( ) ) ;
201
+ } ,
202
+ disableSortBy : true ,
178
203
Cell : cellInfo => {
179
204
return (
180
205
< span data-tip = { `Question #${ Number ( cellInfo . row . id ) + 1 } ` } >
@@ -185,7 +210,14 @@ const Table = () => {
185
210
checked [ cellInfo . row . original . id ] = ! checked [
186
211
cellInfo . row . original . id
187
212
] ;
188
-
213
+ const question = questions . find (
214
+ q => q . id === cellInfo . row . original . id ,
215
+ ) ;
216
+ if ( checked [ cellInfo . row . original . id ] ) {
217
+ question . checkbox = 'Checked' ;
218
+ } else {
219
+ question . checkbox = 'Unchecked' ;
220
+ }
189
221
const additive = checked [ cellInfo . row . original . id ]
190
222
? 1
191
223
: - 1 ;
@@ -194,11 +226,13 @@ const Table = () => {
194
226
] += additive ;
195
227
setDifficultyCount ( difficultyCount ) ;
196
228
setChecked ( [ ...checked ] ) ;
229
+ setData ( filteredByCheckbox ( ) ) ;
197
230
} }
198
231
/>
199
232
</ span >
200
233
) ;
201
234
} ,
235
+ Filter : SelectCheckedColumnFilter ,
202
236
} ,
203
237
{
204
238
Header : 'Questions' ,
@@ -384,6 +418,10 @@ const Table = () => {
384
418
defaultColumn,
385
419
initialState : {
386
420
filters : [
421
+ {
422
+ id : 'checkbox' ,
423
+ value : localStorage . getItem ( 'checkbox' ) || '' ,
424
+ } ,
387
425
{
388
426
id : 'difficulty' ,
389
427
value : localStorage . getItem ( 'difficulty' ) || '' ,
0 commit comments