Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Follow): remove RecommendCircleActivity #4652

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/common/utils/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
): node is NoticeNode & { id: string } =>
node.__typename !== undefined &&
renderableTypes.has(node.__typename) &&
Boolean(node.id)
14 changes: 0 additions & 14 deletions src/views/Follow/Feed/RecommendCircleActivity/gql.ts

This file was deleted.

48 changes: 0 additions & 48 deletions src/views/Follow/Feed/RecommendCircleActivity/index.tsx

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions src/views/Follow/Feed/gql.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -38,9 +37,6 @@ export const FOLLOWING_FEED = gql`
... on ArticleRecommendationActivity {
...RecommendArticleActivity
}
... on CircleRecommendationActivity {
...RecommendCircleActivity
}
... on UserRecommendationActivity {
...RecommendUserActivity
}
Expand All @@ -55,6 +51,5 @@ export const FOLLOWING_FEED = gql`
${UserCreateCircleActivity.fragments}
${UserPublishArticleActivity.fragments}
${RecommendArticleActivity.fragments}
${RecommendCircleActivity.fragments}
${RecommendUserActivity.fragments}
`
72 changes: 38 additions & 34 deletions src/views/Follow/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,13 +18,21 @@ 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'
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 } =
Expand Down Expand Up @@ -92,38 +100,34 @@ const FollowingFeed = () => {
eof
>
<List>
{edges.map(({ node }, i) => (
<List.Item key={`${node.__typename}:${i}`}>
{node.__typename === 'UserPublishArticleActivity' && (
<UserPublishArticleActivity location={i} {...node} />
)}
{node.__typename === 'UserBroadcastCircleActivity' && (
<UserBroadcastCircleActivity {...node} />
)}
{node.__typename === 'UserCreateCircleActivity' && (
<UserCreateCircleActivity location={i} {...node} />
)}
{node.__typename === 'UserAddArticleTagActivity' && (
<UserAddArticleTagActivity location={i} {...node} />
)}
{node.__typename === 'ArticleRecommendationActivity' && (
<RecommendArticleActivity
location={i}
articles={node.recommendArticles}
source={node.source}
/>
)}
{node.__typename === 'CircleRecommendationActivity' && (
<RecommendCircleActivity
location={i}
circles={node.recommendCircles}
/>
)}
{node.__typename === 'UserRecommendationActivity' && (
<RecommendUserActivity users={node.recommendUsers} />
)}
</List.Item>
))}
{edges.map(({ node }, i) => {
return shouldRenderNode(node, renderableTypes) ? (
<List.Item key={`${node.__typename}:${i}`}>
{node.__typename === 'UserPublishArticleActivity' && (
<UserPublishArticleActivity location={i} {...node} />
)}
{node.__typename === 'UserBroadcastCircleActivity' && (
<UserBroadcastCircleActivity {...node} />
)}
{node.__typename === 'UserCreateCircleActivity' && (
<UserCreateCircleActivity location={i} {...node} />
)}
{node.__typename === 'UserAddArticleTagActivity' && (
<UserAddArticleTagActivity location={i} {...node} />
)}
{node.__typename === 'ArticleRecommendationActivity' && (
<RecommendArticleActivity
location={i}
articles={node.recommendArticles}
source={node.source}
/>
)}
{node.__typename === 'UserRecommendationActivity' && (
<RecommendUserActivity users={node.recommendUsers} />
)}
</List.Item>
) : null
})}
</List>
</InfiniteScroll>
</>
Expand Down
38 changes: 12 additions & 26 deletions src/views/Me/Notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -120,7 +106,7 @@ const BaseNotifications = () => {
<List spacing={['xloose', 0]}>
{edges.map(
({ node }) =>
isSpecificNoticeType(node) && (
shouldRenderNode(node, renderableTypes) && (
<List.Item key={node.id}>
<Notice notice={node} />
</List.Item>
Expand Down
Loading