From 6a602045094c09f9aff11fbbd2ad622b10aeb6e0 Mon Sep 17 00:00:00 2001 From: NGUYEN DINH Quoc-Huy <contact@quoc-huy.com> Date: Sun, 19 Apr 2020 19:45:09 +1000 Subject: [PATCH] Closes #38 Don't display community labels outside of community --- src/app/components/cards/PostSummary.jsx | 28 ++++++++++++++------ src/app/components/cards/PostsList.jsx | 8 +----- src/app/components/elements/Author/index.jsx | 6 +++-- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/app/components/cards/PostSummary.jsx b/src/app/components/cards/PostSummary.jsx index 2df991af8..6d99a9502 100644 --- a/src/app/components/cards/PostSummary.jsx +++ b/src/app/components/cards/PostSummary.jsx @@ -1,19 +1,20 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Link } from 'react-router'; +import { connect } from 'react-redux'; +import tt from 'counterpart'; +import { List } from 'immutable'; +import _ from 'lodash'; import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper'; import Icon from 'app/components/elements/Icon'; -import { connect } from 'react-redux'; import Reblog from 'app/components/elements/Reblog'; +import resolveRoute from 'app/ResolveRoute'; import Voting from 'app/components/elements/Voting'; -import { immutableAccessor } from 'app/utils/Accessors'; import { extractBodySummary, extractImageLink } from 'app/utils/ExtractContent'; import VotesAndComments from 'app/components/elements/VotesAndComments'; -import { List, Map } from 'immutable'; import Author from 'app/components/elements/Author'; import Tag from 'app/components/elements/Tag'; import UserNames from 'app/components/elements/UserNames'; -import tt from 'counterpart'; import ImageUserBlockList from 'app/utils/ImageUserBlockList'; import { proxifyImageUrl } from 'app/utils/ProxifyUrl'; import Userpic, { SIZE_SMALL } from 'app/components/elements/Userpic'; @@ -61,8 +62,16 @@ class PostSummary extends React.Component { } render() { + let requestedCategory; + if (typeof window !== 'undefined') { + const route = resolveRoute(window.location.pathname); + if (route.page === 'PostsIndex') { + requestedCategory = _.get(route, 'params[1]'); + } + } + const { ignore, hideCategory, net_vests } = this.props; - const { post, onClose } = this.props; + const { post } = this.props; if (!post) return null; let reblogged_by; @@ -94,6 +103,7 @@ class PostSummary extends React.Component { const permlink = post.get('permlink'); const category = post.get('category'); const post_url = `/${category}/@${author}/${permlink}`; + const showCommunityLabels = requestedCategory === category; const summary = extractBodySummary(post.get('body'), isReply); const content_body = ( @@ -128,6 +138,7 @@ class PostSummary extends React.Component { post={post} follow={false} hideEditor={true} + showRole={showCommunityLabels} /> </span> @@ -160,9 +171,10 @@ class PostSummary extends React.Component { <Icon name="hivepower" /> </span> )} - {post.getIn(['stats', 'is_pinned'], false) && ( - <span className="FeaturedTag">Pinned</span> - )} + {showCommunityLabels && + post.getIn(['stats', 'is_pinned'], false) && ( + <span className="FeaturedTag">Pinned</span> + )} </Link> </div> </div> diff --git a/src/app/components/cards/PostsList.jsx b/src/app/components/cards/PostsList.jsx index b147184c0..7763cfe04 100644 --- a/src/app/components/cards/PostsList.jsx +++ b/src/app/components/cards/PostsList.jsx @@ -1,19 +1,13 @@ import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; -import tt from 'counterpart'; import { List } from 'immutable'; -import * as userActions from 'app/redux/UserReducer'; +import debounce from 'lodash.debounce'; import { actions as fetchDataSagaActions } from 'app/redux/FetchDataSaga'; import PostSummary from 'app/components/cards/PostSummary'; -import Post from 'app/components/pages/Post'; import LoadingIndicator from 'app/components/elements/LoadingIndicator'; -import debounce from 'lodash.debounce'; -import { findParent } from 'app/utils/DomUtils'; -import Icon from 'app/components/elements/Icon'; import GptAd from 'app/components/elements/GptAd'; import VideoAd from 'app/components/elements/VideoAd'; - import shouldComponentUpdate from 'app/utils/shouldComponentUpdate'; function topPosition(domElt) { diff --git a/src/app/components/elements/Author/index.jsx b/src/app/components/elements/Author/index.jsx index 5a7786532..d2269550b 100644 --- a/src/app/components/elements/Author/index.jsx +++ b/src/app/components/elements/Author/index.jsx @@ -37,6 +37,7 @@ class Author extends React.Component { role: string, title: string, community: string, + showRole: bool, }; static defaultProps = { follow: true, @@ -107,7 +108,7 @@ class Author extends React.Component { mute, showAffiliation, blacklists, - + showRole, community, permlink, role, @@ -128,7 +129,7 @@ class Author extends React.Component { community={community} author={author} permlink={permlink} - role={role} + role={showRole ? role : null} title={title} hideEdit={this.props.hideEditor} /> @@ -218,5 +219,6 @@ export default connect((state, props) => { role: post.get('author_role'), // UserTitle title: post.get('author_title'), // UserTitle blacklists: blacklists.length > 0 ? blacklists : null, + showRole: props.showRole, }; })(Author); -- GitLab