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
This commit is contained in:
Julianna Tetreault 2020-12-03 08:59:29 -07:00 committed by GitHub
parent 41fbe24235
commit 28f3dbb13b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();