From 673f0cd232529b080d6da7021d6bbf49233d5e18 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 20 Jul 2017 02:07:40 +0700 Subject: [PATCH] Hide featured comments tab when empty --- .../src/components/Stream.js | 34 ++++++++++++++----- .../client/containers/Tab.js | 3 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/client/coral-embed-stream/src/components/Stream.js b/client/coral-embed-stream/src/components/Stream.js index 2bb1ffaa1..395ca8c3b 100644 --- a/client/coral-embed-stream/src/components/Stream.js +++ b/client/coral-embed-stream/src/components/Stream.js @@ -36,6 +36,21 @@ class Stream extends React.Component { if (!this.userIsDegraged(this.props) && this.userIsDegraged(next)) { this.setState({keepCommentBox: true}); } + + if (next.activeStreamTab !== 'all') { + const slotPlugins = this.getSlotComponents('streamTabs', next).map((c) => c.talkPluginName); + if (slotPlugins.indexOf(next.activeStreamTab) === -1) { + next.setActiveStreamTab('all'); + } + } + } + + getSlotProps({data, root, root: {asset}} = this.props) { + return {data, root, asset}; + } + + getSlotComponents(slot, props = this.props) { + return getSlotComponents(slot, props.reduxState, this.getSlotProps(props)); } setActiveReplyBox = (id) => { @@ -74,7 +89,6 @@ class Stream extends React.Component { loadMoreComments, viewAllComments, auth: {loggedIn, user}, - reduxState, editName } = this.props; const {keepCommentBox} = this.state; @@ -98,7 +112,7 @@ class Stream extends React.Component { }; const showCommentBox = loggedIn && ((!banned && !temporarilySuspended && !highlightedComment) || keepCommentBox); - const streamTabProps = {data, root, asset}; + const slotProps = this.getSlotProps(); if (!comment && !comments) { console.error('Talk: No comments came back from the graph given that query. Please, check the query params.'); @@ -159,8 +173,7 @@ class Stream extends React.Component { {loggedIn && ( @@ -207,13 +220,16 @@ class Stream extends React.Component {
- +
- {getSlotComponents('streamTabs', reduxState, streamTabProps).map((PluginComponent) => ( + {this.getSlotComponents('streamTabs').map((PluginComponent) => ( @@ -223,10 +239,10 @@ class Stream extends React.Component { - {getSlotComponents('streamTabPanes', reduxState, streamTabProps).map((PluginComponent) => ( + {this.getSlotComponents('streamTabPanes').map((PluginComponent) => ( ))} diff --git a/plugins/talk-plugin-featured-comments/client/containers/Tab.js b/plugins/talk-plugin-featured-comments/client/containers/Tab.js index 27c504214..5d92387d6 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/Tab.js +++ b/plugins/talk-plugin-featured-comments/client/containers/Tab.js @@ -1,5 +1,5 @@ import {compose, gql} from 'react-apollo'; -import {withFragments} from 'plugin-api/beta/client/hocs'; +import {withFragments, excludeIf} from 'plugin-api/beta/client/hocs'; import Tab from '../components/Tab'; const enhance = compose( @@ -9,6 +9,7 @@ const enhance = compose( featuredCommentsCount: totalCommentCount(tags: ["FEATURED"], excludeIgnored: $excludeIgnored) }`, }), + excludeIf((props) => props.asset.featuredCommentsCount === 0), ); export default enhance(Tab);