Skip to content

Commit d3198bd

Browse files
hiromikZhongou ZHENG
and
Zhongou ZHENG
authored
Allow sorting by most asked companies to less asked companies (#104)
Co-authored-by: Zhongou ZHENG <zhongou.zheng@gmail.com>
1 parent 408ec1a commit d3198bd

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/components/Table/index.js

+31-7
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const Table = () => {
160160
{
161161
Header: 'Questions',
162162
accessor: 'questions',
163+
disableSortBy: true,
163164
Cell: cellInfo => {
164165
return (
165166
<NavLink
@@ -189,6 +190,7 @@ const Table = () => {
189190
{
190191
Header: 'Solutions',
191192
accessor: 'solutions',
193+
disableSortBy: true,
192194
Cell: cellInfo => {
193195
const url = cellInfo.row.original.premium
194196
? `${cellInfo.row.original.url}/`
@@ -234,6 +236,7 @@ const Table = () => {
234236
);
235237
},
236238
accessor: 'pattern',
239+
disableSortBy: true,
237240
Cell: cellInfo => {
238241
const patterns = `${cellInfo.row.original.pattern}`
239242
.split(',')
@@ -261,6 +264,7 @@ const Table = () => {
261264
{
262265
Header: 'Difficulty',
263266
accessor: 'difficulty',
267+
disableSortBy: true,
264268
Cell: cellInfo => (
265269
<Row>
266270
<Badge
@@ -276,15 +280,27 @@ const Table = () => {
276280
{
277281
Header: () => {
278282
return (
279-
<div style={{ whiteSpace: 'nowrap' }}>
280-
Companies{' '}
281-
<span data-tip="Companies retrieved from Leetcode Premium (May 2021)">
282-
<FaQuestionCircle />
283-
</span>
284-
</div>
283+
<>
284+
<div
285+
style={{ whiteSpace: 'nowrap', display: 'inline-block' }}
286+
>
287+
Companies{' '}
288+
<span data-tip="Companies retrieved from Leetcode Premium (May 2021)">
289+
<FaQuestionCircle />
290+
</span>
291+
</div>
292+
</>
285293
);
286294
},
287295
accessor: 'companies',
296+
sortType: (a, b) => {
297+
if (a.original.companies.length === b.original.companies.length) {
298+
return 0;
299+
}
300+
return a.original.companies.length > b.original.companies.length
301+
? 1
302+
: -1;
303+
},
288304
Cell: cellInfo => {
289305
const companies = cellInfo.row.original.companies.map(company => {
290306
return (
@@ -333,7 +349,15 @@ const Table = () => {
333349
<tr {...headerGroup.getHeaderGroupProps()}>
334350
{headerGroup.headers.map(column => (
335351
<th {...column.getHeaderProps()}>
336-
{column.render('Header')}
352+
<div {...column.getSortByToggleProps({ title: null })}>
353+
{column.render('Header')}
354+
{/* eslint-disable-next-line no-nested-ternary */}
355+
{column.isSorted
356+
? column.isSortedDesc
357+
? ' 🔽'
358+
: ' 🔼'
359+
: ''}
360+
</div>
337361
<div>{column.canFilter ? column.render('Filter') : null}</div>
338362
</th>
339363
))}

0 commit comments

Comments
 (0)