Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0528d4c

Browse files
steviekongsidharth-ping
andauthored
Presist filters between refreshes (#167)
Co-authored-by: steviekong <sidharth@pingthis.in>
1 parent a5f7194 commit 0528d4c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

‎src/components/Table/filters.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
22

3-
function CreateDropDownListHelper(options, filterValue, setFilter) {
3+
function CreateDropDownListHelper(options, filterValue, setFilter,id) {
44
return (
55
<select
66
value={filterValue}
77
onChange={e => {
88
setFilter(e.target.value || '');
9+
localStorage.setItem(id, e.target.value);
910
}}
1011
>
1112
<option value="">All</option>
@@ -37,11 +38,11 @@ export function DefaultColumnFilter({
3738
}
3839

3940
export function SelectDifficultyColumnFilter({
40-
column: { filterValue, setFilter },
41+
column: { filterValue, setFilter, id },
4142
}) {
4243
const options = ['Easy', 'Medium', 'Hard'];
4344

44-
return CreateDropDownListHelper(options, filterValue, setFilter);
45+
return CreateDropDownListHelper(options, filterValue, setFilter,id);
4546
}
4647

4748
export function SelectColumnFilter({
@@ -61,5 +62,5 @@ export function SelectColumnFilter({
6162
return [...set.values()].sort();
6263
}, [id, preFilteredRows]);
6364

64-
return CreateDropDownListHelper(options, filterValue, setFilter);
65+
return CreateDropDownListHelper(options, filterValue, setFilter,id);
6566
}

‎src/components/Table/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ const Table = () => {
280280
},
281281
accessor: 'pattern',
282282
disableSortBy: true,
283+
id: 'pattern',
283284
Cell: cellInfo => {
284285
const patterns = `${cellInfo.row.original.pattern}`
285286
.split(',')
@@ -307,6 +308,7 @@ const Table = () => {
307308
{
308309
Header: 'Difficulty',
309310
accessor: 'difficulty',
311+
id: 'difficulty',
310312
disableSortBy: true,
311313
Cell: cellInfo => (
312314
<Row>
@@ -380,6 +382,22 @@ const Table = () => {
380382
columns,
381383
data,
382384
defaultColumn,
385+
initialState: {
386+
filters: [
387+
{
388+
id: 'difficulty',
389+
value: localStorage.getItem('difficulty') || '',
390+
},
391+
{
392+
id: 'pattern',
393+
value: localStorage.getItem('pattern') || '',
394+
},
395+
{
396+
id: 'companies',
397+
value: localStorage.getItem('companies') || '',
398+
},
399+
],
400+
},
383401
},
384402
useFilters,
385403
useSortBy,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /