From 96f61e6e3f3e79a26a9eaa04a35e0a5f6d2c3809 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 10 Feb 2023 14:20:48 +0800 Subject: [PATCH] Sort first --- src/pages/following.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/following.jsx b/src/pages/following.jsx index c9954e39..8dd19774 100644 --- a/src/pages/following.jsx +++ b/src/pages/following.jsx @@ -25,6 +25,13 @@ function Following({ title, path, id, headerStart }) { const results = await homeIterator.current.next(); const { value } = results; if (value?.length) { + // ENFORCE sort by datetime (Latest first) + value.sort((a, b) => { + const aDate = new Date(a.createdAt); + const bDate = new Date(b.createdAt); + return bDate - aDate; + }); + if (firstLoad) { latestItem.current = value[0].id; } @@ -32,13 +39,6 @@ function Following({ title, path, id, headerStart }) { value.forEach((item) => { saveStatus(item, instance); }); - - // ENFORCE sort by datetime (Latest first) - value.sort((a, b) => { - const aDate = new Date(a.createdAt); - const bDate = new Date(b.createdAt); - return bDate - aDate; - }); } return results; }