From afe27d2da41ab2b729aecd4516746bc43ba1e72a Mon Sep 17 00:00:00 2001 From: Awais Ansari <79941147+awais-ansari@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:35:37 +0500 Subject: [PATCH] fix: pinned post sorting issue (#243) --- src/discussions/posts/PostsList.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/discussions/posts/PostsList.jsx b/src/discussions/posts/PostsList.jsx index 4c9265d0..056db78f 100644 --- a/src/discussions/posts/PostsList.jsx +++ b/src/discussions/posts/PostsList.jsx @@ -1,6 +1,7 @@ import React, { useContext, useEffect } from 'react'; import PropTypes from 'prop-types'; +import uniqBy from 'lodash/uniqBy'; import { useDispatch, useSelector } from 'react-redux'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; @@ -54,7 +55,9 @@ function PostsList({ posts, topics, intl }) { const checkIsSelected = (id) => window.location.pathname.includes(id); let lastPinnedIdx = null; - const postInstances = posts && posts.map((post, idx) => { + const sortedPosts = uniqBy(posts, 'id').sort((a, b) => b.pinned - a.pinned); + + const postInstances = sortedPosts.map((post, idx) => { if (post.pinned && lastPinnedIdx !== false) { lastPinnedIdx = idx; } else if (lastPinnedIdx != null && lastPinnedIdx !== false) {