From ac54001249e184204b375b7fffd0ebde9703197a Mon Sep 17 00:00:00 2001 From: Cheru Berhanu Date: Mon, 26 Aug 2024 12:40:04 -0400 Subject: [PATCH] fix sorting by pushing unparsable dates to bottom (#2231) * fix sorting by pushing unparsable dates to bottom * Update gallery.tsx --- src/pages/gallery/gallery.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/gallery/gallery.tsx b/src/pages/gallery/gallery.tsx index e2a6514505..a4c812a905 100644 --- a/src/pages/gallery/gallery.tsx +++ b/src/pages/gallery/gallery.tsx @@ -64,7 +64,9 @@ export default function Gallery({ games, tags }: { games: GameMetadata[], tags: break; } case SortOrder.TUTORIALS_AND_CHRONOLOGICAL: { - games = games.sort((a, b) => Date.parse(b.addedOn) - Date.parse(a.addedOn)); + games = games.sort((a, b) => + isNaN(Date.parse(b.addedOn)) ? -1 : isNaN(Date.parse(a.addedOn)) ? 1 : Date.parse(b.addedOn) - Date.parse(a.addedOn) + ); // put tutorials first games.sort((a, _) => a.tags.includes("tutorial") ? -1 : 1);