1
- import React from 'react' ;
1
+ import React , { useState , useEffect } from 'react' ;
2
2
import { Container , Row , Col , Badge , NavLink } from 'reactstrap' ;
3
3
import ReactTooltip from 'react-tooltip' ;
4
4
import TableView from './TableView' ;
@@ -11,13 +11,39 @@ import './styles.scss';
11
11
const images = require . context ( '../../icons' , true ) ;
12
12
13
13
const Table = ( ) => {
14
+ const [ checked , setChecked ] = useState (
15
+ JSON . parse ( localStorage . getItem ( 'checked' ) ) ||
16
+ new Array ( questionList . length ) . fill ( false ) ,
17
+ ) ;
18
+
19
+ useEffect ( ( ) => {
20
+ window . localStorage . setItem ( 'checked' , JSON . stringify ( checked ) ) ;
21
+ } , [ checked ] ) ;
22
+
14
23
const data = React . useMemo ( ( ) => questionList , [ ] ) ;
15
24
16
25
const columns = React . useMemo (
17
26
( ) => [
18
27
{
19
28
Header : 'Sort questions by name or pattern!' ,
20
29
columns : [
30
+ {
31
+ id : 'Checkbox' ,
32
+ Cell : rowInfo => {
33
+ return (
34
+ < input
35
+ type = "checkbox"
36
+ className = "checkbox"
37
+ name = { rowInfo . row . original . name }
38
+ checked = { checked [ rowInfo . row . id ] }
39
+ onChange = { ( ) => {
40
+ checked [ rowInfo . row . id ] = ! checked [ rowInfo . row . id ] ;
41
+ setChecked ( [ ...checked ] ) ;
42
+ } }
43
+ />
44
+ ) ;
45
+ } ,
46
+ } ,
21
47
{
22
48
Header : 'Name' ,
23
49
accessor : 'name' ,
@@ -65,7 +91,14 @@ const Table = () => {
65
91
Cell : cellInfo => {
66
92
const companies = cellInfo . row . original . companies . map ( company => {
67
93
const icon = images ( `./${ company } .png` ) ;
68
- return < img src = { icon } alt = { company } data-tip = { company } /> ;
94
+ return (
95
+ < img
96
+ key = { company }
97
+ src = { icon }
98
+ alt = { company }
99
+ data-tip = { company }
100
+ />
101
+ ) ;
69
102
} ) ;
70
103
71
104
return < Row className = "companies" > { companies } </ Row > ;
@@ -75,6 +108,7 @@ const Table = () => {
75
108
] ,
76
109
} ,
77
110
] ,
111
+ // eslint-disable-next-line
78
112
[ ] ,
79
113
) ;
80
114
0 commit comments