Skip to content

Commit

Permalink
fix: show years in descending order
Browse files Browse the repository at this point in the history
  • Loading branch information
nishantwrp committed Jun 4, 2022
1 parent 13569c0 commit f2caee3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/filters/filter-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ FilterModal.propTypes = {
trigger: PropTypes.node.isRequired,
}

FilterModal.defaultProps = {
...FilterTemplate.defaultProps,
}

export default connect(mapStateWithProps, mapDispatchWithProps)(FilterModal)
9 changes: 8 additions & 1 deletion src/components/filters/filter-template.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ class FilterTemplate extends React.Component {
}

getSortedOptionIndexes() {
const sortOrder = this.props.order === "asc" ? 1 : -1

const sortedOptions = this.getAllOptions().sort((a, b) => {
if (this.isOptionSelected(a) ^ this.isOptionSelected(b)) {
return this.isOptionSelected(a) ? -1 : 1
}

if (this.props.sortBy === "name") {
return a.name > b.name ? 1 : -1
return (a.name > b.name ? 1 : -1) * sortOrder
}

if (this.props.sortBy === "frequency") {
Expand Down Expand Up @@ -123,6 +125,11 @@ class FilterTemplate extends React.Component {
FilterTemplate.propTypes = {
name: PropTypes.string.isRequired,
sortBy: PropTypes.oneOf(["name", "frequency"]).isRequired,
order: PropTypes.oneOf(["asc", "desc"]),
}

FilterTemplate.defaultProps = {
order: "asc",
}

export const mapStateWithProps = (state, ownProps) => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/filters/filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Filter extends FilterTemplate {
name={this.props.name}
choices={this.props.choices}
sortBy={this.props.sortBy}
order={this.props.order}
trigger={<div className="filter-view-more">View all</div>}
/>
</div>
Expand All @@ -93,6 +94,7 @@ Filter.propTypes = {
}

Filter.defaultProps = {
...FilterTemplate.defaultProps,
showDivider: true,
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const Sidebar = ({ config, showFilters }) => {
</div>
<Divider className="sidebar-divider" />
<div className="sidebar-content-filters">
<Filter name="years" choices={years} sortBy="name" />
<Filter name="years" choices={years} sortBy="name" order="desc" />
<Filter name="categories" choices={categories} sortBy="name" />
<Filter
name="technologies"
Expand Down

0 comments on commit f2caee3

Please sign in to comment.