From 770f4d92054fbd38928a6f0fed7e7fb3fc4965de Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Mon, 13 Nov 2023 16:57:15 +0800 Subject: [PATCH] Prevent pinned posts from being grouped --- src/components/timeline.jsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/timeline.jsx b/src/components/timeline.jsx index ca2b1d59..f5968a6b 100644 --- a/src/components/timeline.jsx +++ b/src/components/timeline.jsx @@ -65,12 +65,28 @@ function Timeline({ try { let { done, value } = await fetchItems(firstLoad); if (Array.isArray(value)) { + // Avoid grouping for pinned posts + const [pinnedPosts, otherPosts] = value.reduce( + (acc, item) => { + if (item._pinned) { + acc[0].push(item); + } else { + acc[1].push(item); + } + return acc; + }, + [[], []], + ); + value = otherPosts; if (allowGrouping) { if (boostsCarousel) { value = groupBoosts(value); } value = groupContext(value); } + if (pinnedPosts.length) { + value = pinnedPosts.concat(value); + } console.log(value); if (firstLoad) { setItems(value);