Skip to content

Commit

Permalink
Allow sorting by most asked companies to less asked companies (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhongou ZHENG <zhongou.zheng@gmail.com>
  • Loading branch information
hiromik and Zhongou ZHENG committed Jun 6, 2021
1 parent 408ec1a commit d3198bd
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const Table = () => {
{
Header: 'Questions',
accessor: 'questions',
disableSortBy: true,
Cell: cellInfo => {
return (
<NavLink
Expand Down Expand Up @@ -189,6 +190,7 @@ const Table = () => {
{
Header: 'Solutions',
accessor: 'solutions',
disableSortBy: true,
Cell: cellInfo => {
const url = cellInfo.row.original.premium
? `${cellInfo.row.original.url}/`
Expand Down Expand Up @@ -234,6 +236,7 @@ const Table = () => {
);
},
accessor: 'pattern',
disableSortBy: true,
Cell: cellInfo => {
const patterns = `${cellInfo.row.original.pattern}`
.split(',')
Expand Down Expand Up @@ -261,6 +264,7 @@ const Table = () => {
{
Header: 'Difficulty',
accessor: 'difficulty',
disableSortBy: true,
Cell: cellInfo => (
<Row>
<Badge
Expand All @@ -276,15 +280,27 @@ const Table = () => {
{
Header: () => {
return (
<div style={{ whiteSpace: 'nowrap' }}>
Companies{' '}
<span data-tip="Companies retrieved from Leetcode Premium (May 2021)">
<FaQuestionCircle />
</span>
</div>
<>
<div
style={{ whiteSpace: 'nowrap', display: 'inline-block' }}
>
Companies{' '}
<span data-tip="Companies retrieved from Leetcode Premium (May 2021)">
<FaQuestionCircle />
</span>
</div>
</>
);
},
accessor: 'companies',
sortType: (a, b) => {
if (a.original.companies.length === b.original.companies.length) {
return 0;
}
return a.original.companies.length > b.original.companies.length
? 1
: -1;
},
Cell: cellInfo => {
const companies = cellInfo.row.original.companies.map(company => {
return (
Expand Down Expand Up @@ -333,7 +349,15 @@ const Table = () => {
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map(column => (
<th {...column.getHeaderProps()}>
{column.render('Header')}
<div {...column.getSortByToggleProps({ title: null })}>
{column.render('Header')}
{/* eslint-disable-next-line no-nested-ternary */}
{column.isSorted
? column.isSortedDesc
? ' 🔽'
: ' 🔼'
: ''}
</div>
<div>{column.canFilter ? column.render('Filter') : null}</div>
</th>
))}
Expand Down

0 comments on commit d3198bd

Please sign in to comment.