From 7c8338fb1e104f66c55ecbd4d26272586b58d9d5 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:27:34 +0800 Subject: [PATCH 1/4] feat(Follow): remove RecommendCircleActivity --- .../Feed/RecommendCircleActivity/gql.ts | 14 ------ .../Feed/RecommendCircleActivity/index.tsx | 48 ------------------- .../RecommendCircleActivity/styles.module.css | 9 ---- src/views/Follow/Feed/gql.ts | 5 -- src/views/Follow/Feed/index.tsx | 7 --- 5 files changed, 83 deletions(-) delete mode 100644 src/views/Follow/Feed/RecommendCircleActivity/gql.ts delete mode 100644 src/views/Follow/Feed/RecommendCircleActivity/index.tsx delete mode 100644 src/views/Follow/Feed/RecommendCircleActivity/styles.module.css diff --git a/src/views/Follow/Feed/RecommendCircleActivity/gql.ts b/src/views/Follow/Feed/RecommendCircleActivity/gql.ts deleted file mode 100644 index 286706c159..0000000000 --- a/src/views/Follow/Feed/RecommendCircleActivity/gql.ts +++ /dev/null @@ -1,14 +0,0 @@ -import gql from 'graphql-tag' - -import FollowingRecommendCircle from '../FollowingRecommendCircle' - -export const fragments = gql` - fragment RecommendCircleActivity on CircleRecommendationActivity { - recommendCircles: nodes { - ...FollowingFeedRecommendCirclePublic - ...FollowingFeedRecommendCirclePrivate - } - } - ${FollowingRecommendCircle.fragments.circle.public} - ${FollowingRecommendCircle.fragments.circle.private} -` diff --git a/src/views/Follow/Feed/RecommendCircleActivity/index.tsx b/src/views/Follow/Feed/RecommendCircleActivity/index.tsx deleted file mode 100644 index 434cf59712..0000000000 --- a/src/views/Follow/Feed/RecommendCircleActivity/index.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { analytics } from '~/common/utils' -import { Slides } from '~/components' -import { RecommendCircleActivityFragment } from '~/gql/graphql' - -import FollowingRecommendCircle from '../FollowingRecommendCircle' -import FollowingRecommendHead from '../FollowingRecommendHead' -import { fragments } from './gql' -import styles from './styles.module.css' - -interface Props { - circles: RecommendCircleActivityFragment['recommendCircles'] | null - location: number -} - -const RecommendCircleActivity = ({ circles, location }: Props) => { - if (!circles || circles.length <= 0) { - return null - } - - return ( -
- }> - {circles.map((circle, index) => ( - { - analytics.trackEvent('click_feed', { - type: 'following', - contentType: 'CircleRecommendationActivity', - location: `${location}.${index}`, - id: circle.id, - }) - }} - > -
- -
-
- ))} -
-
- ) -} - -RecommendCircleActivity.fragments = fragments - -export default RecommendCircleActivity diff --git a/src/views/Follow/Feed/RecommendCircleActivity/styles.module.css b/src/views/Follow/Feed/RecommendCircleActivity/styles.module.css deleted file mode 100644 index a0e4d16bbe..0000000000 --- a/src/views/Follow/Feed/RecommendCircleActivity/styles.module.css +++ /dev/null @@ -1,9 +0,0 @@ -.container { - padding-bottom: var(--sp8); -} - -.item { - @mixin border-grey; - - border-radius: var(--sp8); -} diff --git a/src/views/Follow/Feed/gql.ts b/src/views/Follow/Feed/gql.ts index 20226260f8..83b04ed971 100644 --- a/src/views/Follow/Feed/gql.ts +++ b/src/views/Follow/Feed/gql.ts @@ -1,7 +1,6 @@ import gql from 'graphql-tag' import RecommendArticleActivity from './RecommendArticleActivity' -import RecommendCircleActivity from './RecommendCircleActivity' import RecommendUserActivity from './RecommendUserActivity' import UserAddArticleTagActivity from './UserAddArticleTagActivity' import UserBroadcastCircleActivity from './UserBroadcastCircleActivity' @@ -38,9 +37,6 @@ export const FOLLOWING_FEED = gql` ... on ArticleRecommendationActivity { ...RecommendArticleActivity } - ... on CircleRecommendationActivity { - ...RecommendCircleActivity - } ... on UserRecommendationActivity { ...RecommendUserActivity } @@ -55,6 +51,5 @@ export const FOLLOWING_FEED = gql` ${UserCreateCircleActivity.fragments} ${UserPublishArticleActivity.fragments} ${RecommendArticleActivity.fragments} - ${RecommendCircleActivity.fragments} ${RecommendUserActivity.fragments} ` diff --git a/src/views/Follow/Feed/index.tsx b/src/views/Follow/Feed/index.tsx index ae7ca870d0..4b0272039c 100644 --- a/src/views/Follow/Feed/index.tsx +++ b/src/views/Follow/Feed/index.tsx @@ -18,7 +18,6 @@ import { FollowingFeedQuery } from '~/gql/graphql' import { FOLLOWING_FEED } from './gql' import RecommendArticleActivity from './RecommendArticleActivity' -import RecommendCircleActivity from './RecommendCircleActivity' import RecommendUserActivity from './RecommendUserActivity' import UserAddArticleTagActivity from './UserAddArticleTagActivity' import UserBroadcastCircleActivity from './UserBroadcastCircleActivity' @@ -113,12 +112,6 @@ const FollowingFeed = () => { source={node.source} /> )} - {node.__typename === 'CircleRecommendationActivity' && ( - - )} {node.__typename === 'UserRecommendationActivity' && ( )} From 89e7428d7ff7e0de1f5de77bfe4e2c5c3f2f777b Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:56:02 +0800 Subject: [PATCH 2/4] fix(Follow): add filter function --- src/views/Follow/Feed/index.tsx | 65 ++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/src/views/Follow/Feed/index.tsx b/src/views/Follow/Feed/index.tsx index 4b0272039c..96abef5c1b 100644 --- a/src/views/Follow/Feed/index.tsx +++ b/src/views/Follow/Feed/index.tsx @@ -80,6 +80,17 @@ const FollowingFeed = () => { }) } + const isRenderNode = (node: any) => { + return ( + node.__typename === 'UserPublishArticleActivity' || + node.__typename === 'UserBroadcastCircleActivity' || + node.__typename === 'UserCreateCircleActivity' || + node.__typename === 'UserAddArticleTagActivity' || + node.__typename === 'ArticleRecommendationActivity' || + node.__typename === 'UserRecommendationActivity' + ) + } + return ( <> { eof > - {edges.map(({ node }, i) => ( - - {node.__typename === 'UserPublishArticleActivity' && ( - - )} - {node.__typename === 'UserBroadcastCircleActivity' && ( - - )} - {node.__typename === 'UserCreateCircleActivity' && ( - - )} - {node.__typename === 'UserAddArticleTagActivity' && ( - - )} - {node.__typename === 'ArticleRecommendationActivity' && ( - - )} - {node.__typename === 'UserRecommendationActivity' && ( - - )} - - ))} + {edges.map(({ node }, i) => { + return isRenderNode(node) ? ( + + {node.__typename === 'UserPublishArticleActivity' && ( + + )} + {node.__typename === 'UserBroadcastCircleActivity' && ( + + )} + {node.__typename === 'UserCreateCircleActivity' && ( + + )} + {node.__typename === 'UserAddArticleTagActivity' && ( + + )} + {node.__typename === 'ArticleRecommendationActivity' && ( + + )} + {node.__typename === 'UserRecommendationActivity' && ( + + )} + + ) : null + })} From 71c280c2acde820a5127458c0d19cac55189ff28 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:01:34 +0800 Subject: [PATCH 3/4] fix(Follow): update function name --- src/views/Follow/Feed/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/Follow/Feed/index.tsx b/src/views/Follow/Feed/index.tsx index 96abef5c1b..c61567f7b2 100644 --- a/src/views/Follow/Feed/index.tsx +++ b/src/views/Follow/Feed/index.tsx @@ -80,7 +80,7 @@ const FollowingFeed = () => { }) } - const isRenderNode = (node: any) => { + const shouldRenderNode = (node: any) => { return ( node.__typename === 'UserPublishArticleActivity' || node.__typename === 'UserBroadcastCircleActivity' || @@ -103,7 +103,7 @@ const FollowingFeed = () => { > {edges.map(({ node }, i) => { - return isRenderNode(node) ? ( + return shouldRenderNode(node) ? ( {node.__typename === 'UserPublishArticleActivity' && ( From 36a5c63d4e63a13418cd7bf43e7c76e80b25cbfe Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:34:21 +0800 Subject: [PATCH 4/4] fix(utils): add shouldRenderNode --- src/common/utils/validator.ts | 13 ++++++++++ src/views/Follow/Feed/index.tsx | 24 ++++++++---------- src/views/Me/Notifications/index.tsx | 38 +++++++++------------------- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/common/utils/validator.ts b/src/common/utils/validator.ts index 2468c4084e..e9058140c0 100644 --- a/src/common/utils/validator.ts +++ b/src/common/utils/validator.ts @@ -53,3 +53,16 @@ export const isValidPaymentPointer = (paymentPointer: string): boolean => paymentPointer.startsWith('$') export const hasUpperCase = (str: string) => str.toLowerCase() !== str + +type NoticeNode = { + __typename?: string + id?: string +} + +export const shouldRenderNode = ( + node: NoticeNode, + renderableTypes: Set +): node is NoticeNode & { id: string } => + node.__typename !== undefined && + renderableTypes.has(node.__typename) && + Boolean(node.id) diff --git a/src/views/Follow/Feed/index.tsx b/src/views/Follow/Feed/index.tsx index c61567f7b2..2fba11885c 100644 --- a/src/views/Follow/Feed/index.tsx +++ b/src/views/Follow/Feed/index.tsx @@ -4,7 +4,7 @@ import _flatten from 'lodash/flatten' import _get from 'lodash/get' import { useIntl } from 'react-intl' -import { analytics, mergeConnections } from '~/common/utils' +import { analytics, mergeConnections, shouldRenderNode } from '~/common/utils' import { EmptyWarning, Head, @@ -24,6 +24,15 @@ import UserBroadcastCircleActivity from './UserBroadcastCircleActivity' import UserCreateCircleActivity from './UserCreateCircleActivity' import UserPublishArticleActivity from './UserPublishArticleActivity' +const renderableTypes = new Set([ + 'UserPublishArticleActivity', + 'UserBroadcastCircleActivity', + 'UserCreateCircleActivity', + 'UserAddArticleTagActivity', + 'ArticleRecommendationActivity', + 'UserRecommendationActivity', +]) + const FollowingFeed = () => { const intl = useIntl() const { data, loading, error, fetchMore } = @@ -80,17 +89,6 @@ const FollowingFeed = () => { }) } - const shouldRenderNode = (node: any) => { - return ( - node.__typename === 'UserPublishArticleActivity' || - node.__typename === 'UserBroadcastCircleActivity' || - node.__typename === 'UserCreateCircleActivity' || - node.__typename === 'UserAddArticleTagActivity' || - node.__typename === 'ArticleRecommendationActivity' || - node.__typename === 'UserRecommendationActivity' - ) - } - return ( <> { > {edges.map(({ node }, i) => { - return shouldRenderNode(node) ? ( + return shouldRenderNode(node, renderableTypes) ? ( {node.__typename === 'UserPublishArticleActivity' && ( diff --git a/src/views/Me/Notifications/index.tsx b/src/views/Me/Notifications/index.tsx index 7a82f5a387..f9fd3af9c4 100644 --- a/src/views/Me/Notifications/index.tsx +++ b/src/views/Me/Notifications/index.tsx @@ -3,7 +3,7 @@ import gql from 'graphql-tag' import { useEffect } from 'react' import { FormattedMessage, useIntl } from 'react-intl' -import { mergeConnections } from '~/common/utils' +import { mergeConnections, shouldRenderNode } from '~/common/utils' import { EmptyNotice, Head, @@ -22,30 +22,16 @@ import { MeNotificationsQuery, } from '~/gql/graphql' -type NoticeNode = { - __typename?: string - id?: string -} - -function isSpecificNoticeType( - node: NoticeNode -): node is NoticeNode & { id: string } { - const validTypes = new Set([ - 'ArticleArticleNotice', - 'CircleNotice', - 'ArticleNotice', - 'CommentCommentNotice', - 'CommentNotice', - 'OfficialAnnouncementNotice', - 'TransactionNotice', - 'UserNotice', - ]) - return ( - node.__typename !== undefined && - validTypes.has(node.__typename) && - Boolean(node.id) - ) -} +const renderableTypes = new Set([ + 'ArticleArticleNotice', + 'CircleNotice', + 'ArticleNotice', + 'CommentCommentNotice', + 'CommentNotice', + 'OfficialAnnouncementNotice', + 'TransactionNotice', + 'UserNotice', +]) const ME_NOTIFICATIONS = gql` query MeNotifications($after: String) { @@ -120,7 +106,7 @@ const BaseNotifications = () => { {edges.map( ({ node }) => - isSpecificNoticeType(node) && ( + shouldRenderNode(node, renderableTypes) && (