From 28f3dbb13b9e3f95fa011d79e84e41a8c45cc7e2 Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Thu, 3 Dec 2020 08:59:29 -0700 Subject: [PATCH] Bug Fix: First Published Post Not Showing Properly in the Feed (#11710) [deploy] * Adds a ternary operator to determine where to splice in Feed.jsx * Add comments to Feed.jsx to explain featuredStory and deleteCount --- app/javascript/articles/Feed.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/javascript/articles/Feed.jsx b/app/javascript/articles/Feed.jsx index 80a85a089..87ca4507c 100644 --- a/app/javascript/articles/Feed.jsx +++ b/app/javascript/articles/Feed.jsx @@ -27,13 +27,18 @@ export const Feed = ({ timeFrame, renderFeed }) => { const feedItems = await getFeedItems(timeFrame); // Ensure first article is one with a main_image + // This is important because the featuredStory will + // appear at the top of the feed, with a larger + // main_image than any of the stories or feed elements. const featuredStory = feedItems.find( (story) => story.main_image !== null, ); - // Remove that first one from the array. + // Remove that first story from the array to + // prevent it from rendering twice in the feed. const index = feedItems.indexOf(featuredStory); - feedItems.splice(index, 1); + const deleteCount = featuredStory ? 1 : 0; + feedItems.splice(index, deleteCount); const subStories = feedItems; const organizedFeedItems = [featuredStory, subStories].flat();