From 8a73f23cb03ea6321cb5f09af075071230e006b6 Mon Sep 17 00:00:00 2001 From: Awais Ansari <79941147+awais-ansari@users.noreply.github.com> Date: Wed, 31 Aug 2022 18:29:21 +0500 Subject: [PATCH] fix: small UI issue and post sorting (#274) * fix: filter pinned, unpinned posts and render separately * fix: UI updates for INF-421 and INF-417 * fix: pin icon moves to left for non privilege user * fix: posts list accessibility issue --- src/components/SearchInfo.jsx | 2 +- src/discussions/learners/LearnerPostsView.jsx | 37 +++++++++--------- src/discussions/learners/LearnersView.jsx | 16 ++++++-- .../learners/learner/LearnerCard.jsx | 2 +- .../learners/learner/LearnerFilterBar.jsx | 2 +- src/discussions/posts/PostsList.jsx | 39 +++++++++---------- src/discussions/posts/PostsView.jsx | 1 + .../posts/post-actions-bar/PostActionsBar.jsx | 3 +- .../posts/post-filter-bar/PostFilterBar.jsx | 2 +- src/discussions/posts/post/PostLink.jsx | 19 ++++++--- src/discussions/utils.js | 15 +++++++ src/index.scss | 6 ++- 12 files changed, 90 insertions(+), 54 deletions(-) diff --git a/src/components/SearchInfo.jsx b/src/components/SearchInfo.jsx index 6c2e061f..fc766cbd 100644 --- a/src/components/SearchInfo.jsx +++ b/src/components/SearchInfo.jsx @@ -16,7 +16,7 @@ function SearchInfo({ onClear, }) { return ( -
+
@@ -126,6 +132,7 @@ function PostLink({
+ {!showDivider && post.pinned &&
} ); @@ -142,7 +149,7 @@ PostLink.propTypes = { PostLink.defaultProps = { learnerTab: false, - showDivider: false, + showDivider: true, idx: -1, }; diff --git a/src/discussions/utils.js b/src/discussions/utils.js index bafca548..28f4b964 100644 --- a/src/discussions/utils.js +++ b/src/discussions/utils.js @@ -1,5 +1,6 @@ /* eslint-disable import/prefer-default-export */ import { getIn } from 'formik'; +import { orderBy, uniqBy } from 'lodash'; import { generatePath, useRouteMatch } from 'react-router'; import { getConfig } from '@edx/frontend-platform'; @@ -238,3 +239,17 @@ export const isPostPreviewAvailable = (htmlNode) => { } return true; }; + +/** + * Helper function to filter posts + * @param {array} posts arrays of posts + * @param {string} filterBy name of post object attribute. un will use for reverse + * condition. like pinned attribute for pinned post and unpinned for non pinned posts. + * @param {string} sortBy name of post object attribute + * @param {string} order order of the sorting list + */ +export const filterPosts = (posts, filterBy, sortBy = 'createdAt', order = 'desc') => orderBy( + uniqBy(posts, 'id').filter( + post => (filterBy.startsWith('un') ? !post[filterBy.slice(2)] : post[filterBy]), + ), [sortBy], [order], +); diff --git a/src/index.scss b/src/index.scss index e8745223..62f69192 100755 --- a/src/index.scss +++ b/src/index.scss @@ -160,4 +160,8 @@ header { .pointer-cursor-hover :hover{ cursor: pointer; -} \ No newline at end of file +} + +.filter-bar:focus-visible, .filter-bar:focus { + outline: none; +}