Skip to content

Commit 67cc06d

Browse files
committed
Update Fork | Resolve conflicts
2 parents 9fd5347 + d45088f commit 67cc06d

File tree

4 files changed

+75
-95
lines changed

4 files changed

+75
-95
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Table/index.js

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
NavLink,
88
} from 'reactstrap';
99
import ReactTooltip from 'react-tooltip';
10-
import { useTable, useFilters } from 'react-table';
10+
import { useTable, useFilters, useSortBy } from 'react-table';
1111
import { FaQuestionCircle } from 'react-icons/fa';
1212
import { Event } from '../Shared/Tracking';
1313

@@ -17,49 +17,10 @@ import './styles.scss';
1717

1818
const images = require.context('../../icons', true);
1919

20-
function DefaultColumnFilter({
21-
column: { filterValue, preFilteredRows, setFilter },
22-
}) {
23-
const count = preFilteredRows.length;
24-
25-
return (
26-
<input
27-
value={filterValue || ''}
28-
onChange={e => {
29-
setFilter(e.target.value || undefined); // Set undefined to remove the filter entirely
30-
}}
31-
placeholder={`Search ${count} questions...`}
32-
/>
33-
);
34-
}
35-
36-
function SelectColumnFilter({
37-
column: { filterValue, setFilter, preFilteredRows, id },
38-
}) {
39-
const options = React.useMemo(() => {
40-
const options = new Set();
41-
preFilteredRows.forEach(row => {
42-
options.add(row.values[id]);
43-
});
44-
return [...options.values()];
45-
}, [id, preFilteredRows]);
46-
47-
return (
48-
<select
49-
value={filterValue}
50-
onChange={e => {
51-
setFilter(e.target.value || undefined);
52-
}}
53-
>
54-
<option value="">All</option>
55-
{options.map((option, i) => (
56-
<option key={i} value={option}>
57-
{option}
58-
</option>
59-
))}
60-
</select>
61-
);
62-
}
20+
const sortByObject = { Easy: 0, Medium: 1, Hard: 2 };
21+
questionList.sort(
22+
(a, b) => sortByObject[a.difficulty] - sortByObject[b.difficulty],
23+
);
6324

6425
const Table = () => {
6526
const [checked, setChecked] = useState(
@@ -71,21 +32,21 @@ const Table = () => {
7132
window.localStorage.setItem('checked', JSON.stringify(checked));
7233
}, [checked]);
7334

35+
const data = React.useMemo(() => questionList, []);
36+
7437
const defaultColumn = React.useMemo(
7538
() => ({
7639
Filter: DefaultColumnFilter,
7740
minWidth: 30,
78-
maxWidth: 10,
41+
maxWidth: 30,
7942
}),
8043
[],
8144
);
8245

83-
const data = React.useMemo(() => questionList, []);
84-
8546
const columns = React.useMemo(
8647
() => [
8748
{
88-
Header: 'Sort questions by name or pattern!',
49+
Header: 'Leetcode Patterns',
8950
columns: [
9051
{
9152
id: 'Checkbox',
@@ -138,7 +99,6 @@ const Table = () => {
13899
{
139100
Header: 'Difficulty',
140101
accessor: 'difficulty',
141-
Filter: SelectColumnFilter,
142102
Cell: cellInfo => (
143103
<Badge
144104
className={cellInfo.row.original.difficulty.toLowerCase()}
@@ -147,6 +107,7 @@ const Table = () => {
147107
{cellInfo.row.original.difficulty}
148108
</Badge>
149109
),
110+
Filter: SelectColumnFilter,
150111
},
151112
{
152113
Header: () => {
@@ -184,6 +145,50 @@ const Table = () => {
184145
[],
185146
);
186147

148+
function DefaultColumnFilter({
149+
column: { filterValue, preFilteredRows, setFilter },
150+
}) {
151+
const count = preFilteredRows.length;
152+
153+
return (
154+
<input
155+
value={filterValue || ''}
156+
onChange={e => {
157+
setFilter(e.target.value || undefined); // Set undefined to remove the filter entirely
158+
}}
159+
placeholder={`Search ${count} questions...`}
160+
/>
161+
);
162+
}
163+
164+
function SelectColumnFilter({
165+
column: { filterValue, setFilter, preFilteredRows, id },
166+
}) {
167+
const options = React.useMemo(() => {
168+
const options = new Set();
169+
preFilteredRows.forEach(row => {
170+
options.add(row.values[id]);
171+
});
172+
return [...options.values()];
173+
}, [id, preFilteredRows]);
174+
175+
return (
176+
<select
177+
value={filterValue}
178+
onChange={e => {
179+
setFilter(e.target.value || undefined);
180+
}}
181+
>
182+
<option value="">All</option>
183+
{options.map((option, i) => (
184+
<option key={i} value={option}>
185+
{option}
186+
</option>
187+
))}
188+
</select>
189+
);
190+
}
191+
187192
const {
188193
getTableProps,
189194
getTableBodyProps,
@@ -195,8 +200,12 @@ const Table = () => {
195200
columns,
196201
data,
197202
defaultColumn,
203+
initialState: {
204+
sortBy: [{ id: 'pattern' }],
205+
},
198206
},
199207
useFilters,
208+
useSortBy,
200209
);
201210

202211
return (

src/data/index.js

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,91 +1826,62 @@ export default [
18261826
url: 'https://leetcode.com/problems/longest-word-in-dictionary/',
18271827
pattern: 'Trie',
18281828
difficulty: 'Easy',
1829-
companies: [
1830-
'Goldman Sachs',
1831-
'Google',
1832-
],
1829+
companies: ['Goldman Sachs', 'Google',],
18331830
},
18341831
{
18351832
id: 165,
18361833
name: 'Index Pairs of a String',
18371834
url: 'https://leetcode.com/problems/index-pairs-of-a-string/',
18381835
pattern: 'Trie',
18391836
difficulty: 'Easy',
1840-
companies: [
1841-
'Amazon',
1842-
],
1837+
companies: ['Amazon',],
18431838
},
18441839
{
18451840
id: 166,
18461841
name: 'Maximum XOR of Two Numbers in an Array',
18471842
url: 'https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array',
18481843
pattern: 'Trie',
18491844
difficulty: 'Medium',
1850-
companies: [
1851-
'Google',
1852-
],
1845+
companies: ['Google'],
18531846
},
18541847
{
18551848
id: 167,
18561849
name: 'Concatenated Words',
18571850
url: 'https://leetcode.com/problems/concatenated-words/',
18581851
pattern: 'Trie',
18591852
difficulty: 'Hard',
1860-
companies: [
1861-
'Amazon',
1862-
'Apple',
1863-
'Facebook',
1864-
],
1853+
companies: ['Amazon', 'Apple', 'Facebook'],
18651854
},
18661855
{
18671856
id: 168,
18681857
name: 'Prefix and Suffix Search',
18691858
url: 'https://leetcode.com/problems/prefix-and-suffix-search/',
18701859
pattern: 'Trie',
18711860
difficulty: 'Hard',
1872-
companies: [
1873-
'Facebook',
1874-
'Google',
1875-
'Uber',
1876-
],
1861+
companies: ['Facebook', 'Google', 'Uber'],
18771862
},
18781863
{
18791864
id: 169,
18801865
name: 'Palindrome Pairs',
18811866
url: 'https://leetcode.com/problems/palindrome-pairs/',
18821867
pattern: 'Trie',
18831868
difficulty: 'Hard',
1884-
companies: [
1885-
'Airbnb',
1886-
'Amazon',
1887-
'Facebook',
1888-
'Google',
1889-
'Square',
1890-
],
1869+
companies: ['Airbnb', 'Amazon', 'Facebook', 'Google', 'Square'],
18911870
},
18921871
{
18931872
id: 170,
18941873
name: 'Design Search Autocomplete System',
18951874
url: 'https://leetcode.com/problems/design-search-autocomplete-system/',
18961875
pattern: 'Trie',
18971876
difficulty: 'Hard',
1898-
companies: [
1899-
'Amazon',
1900-
'Google',
1901-
'Lyft',
1902-
'Microsoft',
1903-
'Uber',
1904-
],
1877+
companies: ['Amazon', 'Google', 'Lyft', 'Microsoft', 'Uber'],
19051878
},
19061879
{
19071880
id: 171,
19081881
name: 'Word Squares',
19091882
url: 'https://leetcode.com/problems/word-squares/',
19101883
pattern: 'Trie',
19111884
difficulty: 'Hard',
1912-
companies: [
1913-
'Oracle',
1914-
],
1885+
companies: ['Oracle'],
19151886
},
19161887
];

src/icons/Square.png

1.46 KB
Loading

0 commit comments

Comments
 (0)