diff --git a/package-lock.json b/package-lock.json index a53b7850..c6e92576 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5433,9 +5433,9 @@ "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, "eventemitter3": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.0.tgz", - "integrity": "sha512-qerSRB0p+UDEssxTtm6EDKcE7W4OaoisfIMl4CngyEhjpYglocpNg6UEqCvemdGhosAsg4sO2dXJOdyBifPGCg==" + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.4.tgz", + "integrity": "sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ==" }, "events": { "version": "3.1.0", @@ -6014,9 +6014,9 @@ } }, "follow-redirects": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.10.0.tgz", - "integrity": "sha512-4eyLK6s6lH32nOvLLwlIOnr9zrL8Sm+OvW4pVTJNoXeGzYIkHVf+pADQi+OJ0E67hiuSLezPVPyBcIZO50TmmQ==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.11.0.tgz", + "integrity": "sha512-KZm0V+ll8PfBrKwMzdo5D13b1bur9Iq9Zd/RMmAoQQcl2PxxFml8cxXPaaPYVbV0RjNjq1CU7zIzAOqtUPudmA==", "requires": { "debug": "^3.0.0" }, @@ -6785,9 +6785,9 @@ "integrity": "sha1-ksnBN0w1CF912zWexWzCV8u5P6Q=" }, "http-proxy": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.0.tgz", - "integrity": "sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==", + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", "requires": { "eventemitter3": "^4.0.0", "follow-redirects": "^1.0.0", diff --git a/src/components/Table/index.js b/src/components/Table/index.js index 62f1d946..c1564271 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -7,7 +7,7 @@ import { NavLink, } from 'reactstrap'; import ReactTooltip from 'react-tooltip'; -import { useTable, useFilters } from 'react-table'; +import { useTable, useFilters, useSortBy } from 'react-table'; import { FaQuestionCircle } from 'react-icons/fa'; import { Event } from '../Shared/Tracking'; @@ -17,49 +17,10 @@ import './styles.scss'; const images = require.context('../../icons', true); -function DefaultColumnFilter({ - column: { filterValue, preFilteredRows, setFilter }, -}) { - const count = preFilteredRows.length; - - return ( - { - setFilter(e.target.value || undefined); // Set undefined to remove the filter entirely - }} - placeholder={`Search ${count} questions...`} - /> - ); -} - -function SelectColumnFilter({ - column: { filterValue, setFilter, preFilteredRows, id }, -}) { - const options = React.useMemo(() => { - const options = new Set(); - preFilteredRows.forEach(row => { - options.add(row.values[id]); - }); - return [...options.values()]; - }, [id, preFilteredRows]); - - return ( - - ); -} +const sortByObject = { Easy: 0, Medium: 1, Hard: 2 }; +questionList.sort( + (a, b) => sortByObject[a.difficulty] - sortByObject[b.difficulty], +); const Table = () => { const [checked, setChecked] = useState( @@ -71,21 +32,21 @@ const Table = () => { window.localStorage.setItem('checked', JSON.stringify(checked)); }, [checked]); + const data = React.useMemo(() => questionList, []); + const defaultColumn = React.useMemo( () => ({ Filter: DefaultColumnFilter, minWidth: 30, - maxWidth: 10, + maxWidth: 30, }), [], ); - const data = React.useMemo(() => questionList, []); - const columns = React.useMemo( () => [ { - Header: 'Sort questions by name or pattern!', + Header: 'Leetcode Patterns', columns: [ { id: 'Checkbox', @@ -138,7 +99,6 @@ const Table = () => { { Header: 'Difficulty', accessor: 'difficulty', - Filter: SelectColumnFilter, Cell: cellInfo => ( { {cellInfo.row.original.difficulty} ), + Filter: SelectColumnFilter, }, { Header: () => { @@ -184,6 +145,50 @@ const Table = () => { [], ); + function DefaultColumnFilter({ + column: { filterValue, preFilteredRows, setFilter }, + }) { + const count = preFilteredRows.length; + + return ( + { + setFilter(e.target.value || undefined); // Set undefined to remove the filter entirely + }} + placeholder={`Search ${count} questions...`} + /> + ); + } + + function SelectColumnFilter({ + column: { filterValue, setFilter, preFilteredRows, id }, + }) { + const options = React.useMemo(() => { + const options = new Set(); + preFilteredRows.forEach(row => { + options.add(row.values[id]); + }); + return [...options.values()]; + }, [id, preFilteredRows]); + + return ( + + ); + } + const { getTableProps, getTableBodyProps, @@ -195,8 +200,12 @@ const Table = () => { columns, data, defaultColumn, + initialState: { + sortBy: [{ id: 'pattern' }], + }, }, useFilters, + useSortBy, ); return ( diff --git a/src/data/index.js b/src/data/index.js index d18b51fb..edff96d3 100644 --- a/src/data/index.js +++ b/src/data/index.js @@ -1592,7 +1592,7 @@ export default [ id: 147, name: 'Implement Trie (Prefix Tree)', url: 'https://leetcode.com/problems/implement-trie-prefix-tree/', - pattern: 'DFS', + pattern: 'Trie', difficulty: 'Medium', companies: ['Amazon', 'Microsoft', 'Google', 'Facebook'], }, @@ -1626,7 +1626,7 @@ export default [ id: 150, name: 'Word Search II', url: 'https://leetcode.com/problems/word-search-ii/', - pattern: 'DFS', + pattern: 'Trie', difficulty: 'Hard', companies: [ 'Amazon', @@ -1820,4 +1820,68 @@ export default [ 'Bloomberg', ], }, + { + id: 164, + name: 'Longest Word in Dictionary', + url: 'https://leetcode.com/problems/longest-word-in-dictionary/', + pattern: 'Trie', + difficulty: 'Easy', + companies: ['Goldman Sachs', 'Google'], + }, + { + id: 165, + name: 'Index Pairs of a String', + url: 'https://leetcode.com/problems/index-pairs-of-a-string/', + pattern: 'Trie', + difficulty: 'Easy', + companies: ['Amazon'], + }, + { + id: 166, + name: 'Maximum XOR of Two Numbers in an Array', + url: 'https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array', + pattern: 'Trie', + difficulty: 'Medium', + companies: ['Google'], + }, + { + id: 167, + name: 'Concatenated Words', + url: 'https://leetcode.com/problems/concatenated-words/', + pattern: 'Trie', + difficulty: 'Hard', + companies: ['Amazon', 'Apple', 'Facebook'], + }, + { + id: 168, + name: 'Prefix and Suffix Search', + url: 'https://leetcode.com/problems/prefix-and-suffix-search/', + pattern: 'Trie', + difficulty: 'Hard', + companies: ['Facebook', 'Google', 'Uber'], + }, + { + id: 169, + name: 'Palindrome Pairs', + url: 'https://leetcode.com/problems/palindrome-pairs/', + pattern: 'Trie', + difficulty: 'Hard', + companies: ['Airbnb', 'Amazon', 'Facebook', 'Google', 'Square'], + }, + { + id: 170, + name: 'Design Search Autocomplete System', + url: 'https://leetcode.com/problems/design-search-autocomplete-system/', + pattern: 'Trie', + difficulty: 'Hard', + companies: ['Amazon', 'Google', 'Lyft', 'Microsoft', 'Uber'], + }, + { + id: 171, + name: 'Word Squares', + url: 'https://leetcode.com/problems/word-squares/', + pattern: 'Trie', + difficulty: 'Hard', + companies: ['Oracle'], + }, ]; diff --git a/src/icons/Square.png b/src/icons/Square.png new file mode 100644 index 00000000..68c0b23b Binary files /dev/null and b/src/icons/Square.png differ