Solved an issue with sorting

This commit is contained in:
Tiago Ribeiro
2024-01-21 13:34:48 +00:00
parent 83b8ab7774
commit da93b79c78

View File

@@ -2,8 +2,8 @@ import moment from "moment";
export function dateSorter(a: any, b: any, direction: "asc" | "desc", key: string) {
if (!a[key] && !b[key]) return 0;
if (a[key] && !b[key]) return direction === "asc" ? -1 : 1;
if (!a[key] && b[key]) return direction === "asc" ? 1 : -1;
if (a[key] && !b[key]) return direction === "asc" ? 1 : -1;
if (!a[key] && b[key]) return direction === "asc" ? -1 : 1;
if (moment(a[key]).isAfter(b[key])) return direction === "asc" ? 1 : -1;
if (moment(b[key]).isAfter(a[key])) return direction === "asc" ? -1 : 1;
return 0;