Skip to content

Commit 180e201

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add checkboxes to save completed questions
1 parent 8798315 commit 180e201

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

web/src/components/Table/index.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import { Container, Row, Col, Badge, NavLink } from 'reactstrap';
33
import ReactTooltip from 'react-tooltip';
44
import TableView from './TableView';
@@ -11,13 +11,39 @@ import './styles.scss';
1111
const images = require.context('../../icons', true);
1212

1313
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+
1423
const data = React.useMemo(() => questionList, []);
1524

1625
const columns = React.useMemo(
1726
() => [
1827
{
1928
Header: 'Sort questions by name or pattern!',
2029
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+
},
2147
{
2248
Header: 'Name',
2349
accessor: 'name',
@@ -65,7 +91,14 @@ const Table = () => {
6591
Cell: cellInfo => {
6692
const companies = cellInfo.row.original.companies.map(company => {
6793
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+
);
69102
});
70103

71104
return <Row className="companies">{companies}</Row>;
@@ -75,6 +108,7 @@ const Table = () => {
75108
],
76109
},
77110
],
111+
// eslint-disable-next-line
78112
[],
79113
);
80114

0 commit comments

Comments
 (0)