From 043d5fdcec7313fd6a94b15d4924bdd0797bde30 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 18 Jul 2017 16:39:06 +0700 Subject: [PATCH] Handle ignore user --- .../client/containers/Tab.js | 2 +- .../client/containers/TabPane.js | 46 +++++++++---------- .../client/index.js | 25 +++++++++- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/plugins/talk-plugin-featured-comments/client/containers/Tab.js b/plugins/talk-plugin-featured-comments/client/containers/Tab.js index a5f487f8f..790291841 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/Tab.js +++ b/plugins/talk-plugin-featured-comments/client/containers/Tab.js @@ -6,7 +6,7 @@ const enhance = compose( withFragments({ asset: gql` fragment TalkFeatured_Tab_asset on Asset { - featuredCommentsCount: totalCommentCount(tags: ["FEATURED"]) + featuredCommentsCount: totalCommentCount(tags: ["FEATURED"], excludeIgnored: $excludeIgnored) }`, }), ); diff --git a/plugins/talk-plugin-featured-comments/client/containers/TabPane.js b/plugins/talk-plugin-featured-comments/client/containers/TabPane.js index c486b2dc4..2c33fb5b9 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/TabPane.js +++ b/plugins/talk-plugin-featured-comments/client/containers/TabPane.js @@ -16,31 +16,31 @@ const enhance = compose( asset: gql` fragment TalkFeatured_TabPane_asset on Asset { id - featuredComments: comments(tags: ["FEATURED"], deep: true) { - nodes { - id - body - created_at - replyCount - tags { - tag { - name - } - } - action_summaries { - ... on LikeActionSummary { - count - current_user { - id - } - } - } - user { - id - username - } + featuredComments: comments(tags: ["FEATURED"], excludeIgnored: $excludeIgnored, deep: true) { + nodes { + id + body + created_at + replyCount + tags { + tag { + name } + } + action_summaries { + ... on LikeActionSummary { + count + current_user { + id + } + } + } + user { + id + username + } } + } }`, }), ); diff --git a/plugins/talk-plugin-featured-comments/client/index.js b/plugins/talk-plugin-featured-comments/client/index.js index 02a3ed2d4..18ec28901 100644 --- a/plugins/talk-plugin-featured-comments/client/index.js +++ b/plugins/talk-plugin-featured-comments/client/index.js @@ -16,10 +16,31 @@ export default { commentReactions: [FeaturedButton] }, mutations: { + IgnoreUser: ({variables}) => ({ + updateQueries: { + CoralEmbedStream_Embed: (previous) => { + const ignoredUserId = variables.id; + const updated = update(previous, { + asset: { + featuredComments: { + nodes: { + $apply: (nodes) => + nodes.filter((n) => n.user.id !== ignoredUserId) + } + }, + featuredCommentsCount: { + $apply: (value) => value - 1 + } + } + }); + return updated; + } + } + }), AddTag: ({variables}) => ({ updateQueries: { CoralEmbedStream_Embed: (previous) => { - + if (variables.name !== 'FEATURED') { return; } @@ -55,7 +76,7 @@ export default { asset: { featuredComments: { nodes: { - $apply: (nodes) => + $apply: (nodes) => nodes.filter((n) => n.id !== variables.id) } },