From 4c1485193ab4acd35ca33207d67052d5e4bed4b6 Mon Sep 17 00:00:00 2001 From: Rushikesh Tarapure Date: Thu, 7 Apr 2022 13:58:40 +0530 Subject: [PATCH] feat : sorting by creation time/date added --- src/utils/getSortedbydate.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/utils/getSortedbydate.js diff --git a/src/utils/getSortedbydate.js b/src/utils/getSortedbydate.js new file mode 100644 index 0000000..26a4b32 --- /dev/null +++ b/src/utils/getSortedbydate.js @@ -0,0 +1,12 @@ +export const sortbydate = (state, notes) => { + if (state.sortby === "old") { + return [...notes].sort( + (a, b) => Date.parse(a.Note.createdAt) - Date.parse(b.Note.createdAt) + ); + } else if (state.sortby === "new") { + return [...notes].sort( + (a, b) => Date.parse(b.Note.createdAt) - Date.parse(a.Note.createdAt) + ); + } + return notes; + }; \ No newline at end of file