From 7b7cec5258eda91c24133c4d840c59d1dab0bf5b Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 30 Jul 2019 22:48:52 +0000 Subject: [PATCH] feat: switch to comments tab if on featured (#2437) --- .../PostCommentFormContainer.spec.tsx | 2 ++ .../PostCommentForm/PostCommentFormContainer.tsx | 7 +++++++ .../tabs/Comments/Stream/StreamContainer.tsx | 15 ++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx index d7f123bcf..ef5d44bc6 100644 --- a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx +++ b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx @@ -22,6 +22,8 @@ function createDefaultProps(add: DeepPartial = {}): Props { showAuthPopup: noop as any, createComment: noop as any, refreshSettings: noop as any, + tab: "", + onChangeTab: noop as any, story: { id: "story-id", isClosed: false, diff --git a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx index 30e706096..75676b2ec 100644 --- a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx +++ b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx @@ -17,6 +17,7 @@ import { PropTypesOf } from "coral-framework/types"; import { PostCommentFormContainer_settings } from "coral-stream/__generated__/PostCommentFormContainer_settings.graphql"; import { PostCommentFormContainer_story } from "coral-stream/__generated__/PostCommentFormContainer_story.graphql"; import { PostCommentFormContainer_viewer } from "coral-stream/__generated__/PostCommentFormContainer_viewer.graphql"; +import { COMMENTS_TAB } from "coral-stream/__generated__/StreamContainerLocal.graphql"; import { ShowAuthPopupMutation, withShowAuthPopupMutation, @@ -45,6 +46,8 @@ interface Props { viewer: PostCommentFormContainer_viewer | null; story: PostCommentFormContainer_story; showAuthPopup: ShowAuthPopupMutation; + tab: COMMENTS_TAB; + onChangeTab: (tab: COMMENTS_TAB) => void; } interface State { @@ -112,6 +115,10 @@ export class PostCommentFormContainer extends Component { typeof PostCommentForm >["onSubmit"] = async (input, form) => { try { + if (this.props.tab === "FEATURED_COMMENTS") { + await this.props.onChangeTab("ALL_COMMENTS"); + } + const submitStatus = getSubmitStatus( await this.props.createComment({ storyID: this.props.story.id, diff --git a/src/core/client/stream/tabs/Comments/Stream/StreamContainer.tsx b/src/core/client/stream/tabs/Comments/Stream/StreamContainer.tsx index 12f6c43e6..2f18d9832 100644 --- a/src/core/client/stream/tabs/Comments/Stream/StreamContainer.tsx +++ b/src/core/client/stream/tabs/Comments/Stream/StreamContainer.tsx @@ -7,7 +7,10 @@ import { GQLUSER_STATUS } from "coral-framework/schema"; import { StreamContainer_settings as SettingsData } from "coral-stream/__generated__/StreamContainer_settings.graphql"; import { StreamContainer_story as StoryData } from "coral-stream/__generated__/StreamContainer_story.graphql"; import { StreamContainer_viewer as ViewerData } from "coral-stream/__generated__/StreamContainer_viewer.graphql"; -import { StreamContainerLocal } from "coral-stream/__generated__/StreamContainerLocal.graphql"; +import { + COMMENTS_TAB, + StreamContainerLocal, +} from "coral-stream/__generated__/StreamContainerLocal.graphql"; import { UserBoxContainer } from "coral-stream/common/UserBox"; import { Counter, @@ -66,7 +69,7 @@ export const StreamContainer: FunctionComponent = props => { [setLocal] ); const onChangeTab = useCallback( - (tab: any) => setLocal({ commentsTab: tab }), + (tab: COMMENTS_TAB) => setLocal({ commentsTab: tab }), [setLocal] ); const banned = Boolean( @@ -84,12 +87,12 @@ export const StreamContainer: FunctionComponent = props => { // If the selected tab is FEATURED_COMMENTS, but there aren't any featured // comments, then switch it to the all comments tab. if (featuredCommentsCount === 0) { - setLocal({ commentsTab: "ALL_COMMENTS" }); + onChangeTab("ALL_COMMENTS"); } else { - setLocal({ commentsTab: "FEATURED_COMMENTS" }); + onChangeTab("FEATURED_COMMENTS"); } } - }, [featuredCommentsCount, local.commentsTab, setLocal]); + }, [featuredCommentsCount, local.commentsTab, onChangeTab]); return ( <> @@ -102,6 +105,8 @@ export const StreamContainer: FunctionComponent = props => { settings={props.settings} story={props.story} viewer={props.viewer} + tab={local.commentsTab} + onChangeTab={onChangeTab} /> )} {banned && }