fix sorting by year and rating bug
This commit is contained in:
@@ -10,6 +10,8 @@ export default ({ data, limit }) => {
|
|||||||
.slice(0, limit || data.allBooksJson.edges.length)
|
.slice(0, limit || data.allBooksJson.edges.length)
|
||||||
.sort(compareFunctions[sortBy]);
|
.sort(compareFunctions[sortBy]);
|
||||||
|
|
||||||
|
console.log(getSortedBooks());
|
||||||
|
|
||||||
const handleSortByItemClick = (field) => {
|
const handleSortByItemClick = (field) => {
|
||||||
setSortBy(field);
|
setSortBy(field);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { Dropdown } from 'react-bootstrap';
|
|||||||
|
|
||||||
export const compareFunctions = {
|
export const compareFunctions = {
|
||||||
title: ({ node: bookOne }, { node: bookTwo }) => bookOne.title.localeCompare(bookTwo.title),
|
title: ({ node: bookOne }, { node: bookTwo }) => bookOne.title.localeCompare(bookTwo.title),
|
||||||
year: ({ node: bookOne }, { node: bookTwo }) => bookTwo.year - bookOne.year,
|
year: ({ node: bookOne }, { node: bookTwo }) => Number(bookTwo.year) - Number(bookOne.year),
|
||||||
rating: ({ node: bookOne }, { node: bookTwo }) => bookTwo.rating - bookOne.rating,
|
rating: ({ node: bookOne }, { node: bookTwo }) => Number(bookTwo.rating) - Number(bookOne.rating),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FIELDS_TO_SORT_BY = ['rating', 'year', 'title'];
|
export const FIELDS_TO_SORT_BY = ['rating', 'year', 'title'];
|
||||||
|
|||||||
Reference in New Issue
Block a user