fix sorting by year and rating bug

This commit is contained in:
Gal Elmalah
2020-10-11 11:59:15 +03:00
committed by Vishnu Ks
parent e50712e5bc
commit a1fa7011cd
2 changed files with 4 additions and 2 deletions

View File

@@ -10,6 +10,8 @@ export default ({ data, limit }) => {
.slice(0, limit || data.allBooksJson.edges.length)
.sort(compareFunctions[sortBy]);
console.log(getSortedBooks());
const handleSortByItemClick = (field) => {
setSortBy(field);
};

View File

@@ -3,8 +3,8 @@ import { Dropdown } from 'react-bootstrap';
export const compareFunctions = {
title: ({ node: bookOne }, { node: bookTwo }) => bookOne.title.localeCompare(bookTwo.title),
year: ({ node: bookOne }, { node: bookTwo }) => bookTwo.year - bookOne.year,
rating: ({ node: bookOne }, { node: bookTwo }) => bookTwo.rating - bookOne.rating,
year: ({ node: bookOne }, { node: bookTwo }) => Number(bookTwo.year) - Number(bookOne.year),
rating: ({ node: bookOne }, { node: bookTwo }) => Number(bookTwo.rating) - Number(bookOne.rating),
};
export const FIELDS_TO_SORT_BY = ['rating', 'year', 'title'];