diff --git a/src/app/Scenes/Activity/ActivityList.tsx b/src/app/Scenes/Activity/ActivityList.tsx index f768a81df65..a89fff0d870 100644 --- a/src/app/Scenes/Activity/ActivityList.tsx +++ b/src/app/Scenes/Activity/ActivityList.tsx @@ -24,7 +24,9 @@ export const ActivityList: React.FC = ({ viewer, type }) => { const notificationsNodes = extractNodes(data?.notificationsConnection) - const notifications = notificationsNodes.filter(shouldDisplayNotification) + const notifications = notificationsNodes.filter((notification) => + shouldDisplayNotification(notification, "list") + ) const handleLoadMore = () => { if (!hasNext || isLoadingNext) { @@ -127,6 +129,8 @@ const notificationsConnectionFragment = graphql` totalCount } item { + __typename + ... on ViewingRoomPublishedNotificationItem { viewingRoomsConnection(first: 1) { totalCount @@ -138,7 +142,11 @@ const notificationsConnectionFragment = graphql` internalID } } + ... on CollectorProfileUpdatePromptNotificationItem { + __typename + } } + ...ActivityItem_notification } } diff --git a/src/app/Scenes/Activity/utils/__tests__/shouldDisplayNotification.tests.ts b/src/app/Scenes/Activity/utils/__tests__/shouldDisplayNotification.tests.ts index f9b8734936a..d90d4c0d71d 100644 --- a/src/app/Scenes/Activity/utils/__tests__/shouldDisplayNotification.tests.ts +++ b/src/app/Scenes/Activity/utils/__tests__/shouldDisplayNotification.tests.ts @@ -28,7 +28,10 @@ describe("shouldDisplayNotification", () => { const result4 = shouldDisplayNotification({ notificationType: "VIEWING_ROOM_PUBLISHED", artworks: undefined, - item: { viewingRoomsConnection: { totalCount: 1 } }, + item: { + viewingRoomsConnection: { totalCount: 1 }, + __typename: "ViewingRoomPublishedNotificationItem", + }, }) expect(result4).toEqual(true) @@ -36,7 +39,7 @@ describe("shouldDisplayNotification", () => { const result5 = shouldDisplayNotification({ notificationType: "ARTICLE_FEATURED_ARTIST", artworks: undefined, - item: { article: { internalID: "1" } }, + item: { article: { internalID: "1" }, __typename: "ArticleFeaturedArtistNotificationItem" }, }) expect(result5).toEqual(true) }) @@ -68,7 +71,10 @@ describe("shouldDisplayNotification", () => { const result4 = shouldDisplayNotification({ notificationType: "VIEWING_ROOM_PUBLISHED", artworks: undefined, - item: { viewingRoomsConnection: { totalCount: 0 } }, + item: { + viewingRoomsConnection: { totalCount: 0 }, + __typename: "ViewingRoomPublishedNotificationItem", + }, }) expect(result4).toEqual(false) @@ -76,7 +82,10 @@ describe("shouldDisplayNotification", () => { const result5 = shouldDisplayNotification({ notificationType: "ARTICLE_FEATURED_ARTIST", artworks: undefined, - item: {}, + item: { + article: null, + __typename: "ArticleFeaturedArtistNotificationItem", + }, }) expect(result5).toEqual(false) }) diff --git a/src/app/Scenes/Activity/utils/shouldDisplayNotification.ts b/src/app/Scenes/Activity/utils/shouldDisplayNotification.ts index d07ef5eb702..fc760531c03 100644 --- a/src/app/Scenes/Activity/utils/shouldDisplayNotification.ts +++ b/src/app/Scenes/Activity/utils/shouldDisplayNotification.ts @@ -1,15 +1,18 @@ import { ActivityList_viewer$data } from "__generated__/ActivityList_viewer.graphql" +import { ActivityRail_viewer$data } from "__generated__/ActivityRail_viewer.graphql" import { isArtworksBasedNotification } from "app/Scenes/Activity/utils/isArtworksBasedNotification" +import { ExtractNodeType } from "app/utils/relayHelpers" -export type NotificationNode = NonNullable< - NonNullable["edges"]>[0] ->["node"] +export type NotificationNode = + | ExtractNodeType + | ExtractNodeType export const shouldDisplayNotification = ( notification: | Pick, "notificationType" | "artworks" | "item"> | null - | undefined + | undefined, + mode: "rail" | "list" = "list" ) => { if (!notification) { return false @@ -20,14 +23,21 @@ export const shouldDisplayNotification = ( return artworksCount > 0 } - if (notification.notificationType === "VIEWING_ROOM_PUBLISHED") { + if (notification.item?.__typename === "ViewingRoomPublishedNotificationItem") { const viewingRoomsCount = notification.item?.viewingRoomsConnection?.totalCount ?? 0 return viewingRoomsCount > 0 } - if (notification.notificationType === "ARTICLE_FEATURED_ARTIST") { + if (notification.item?.__typename === "ArticleFeaturedArtistNotificationItem") { return !!notification.item?.article?.internalID } + if ( + mode === "rail" && + notification.item?.__typename === "CollectorProfileUpdatePromptNotificationItem" + ) { + return false + } + return true } diff --git a/src/app/Scenes/HomeView/Components/ActivityRail.tsx b/src/app/Scenes/HomeView/Components/ActivityRail.tsx index 1267b87c417..7253ae52ca1 100644 --- a/src/app/Scenes/HomeView/Components/ActivityRail.tsx +++ b/src/app/Scenes/HomeView/Components/ActivityRail.tsx @@ -23,8 +23,9 @@ export const ActivityRail: React.FC = ({ title, viewer }) => const notificationsNodes = extractNodes(data?.notificationsConnection) - const notifications = notificationsNodes.filter(shouldDisplayNotification) - + const notifications = notificationsNodes.filter((notification) => + shouldDisplayNotification(notification, "rail") + ) if (notifications.length === 0) { return null } @@ -79,18 +80,25 @@ const notificationsConnectionFragment = graphql` totalCount } item { + __typename + ... on ViewingRoomPublishedNotificationItem { viewingRoomsConnection(first: 1) { totalCount } } + ... on CollectorProfileUpdatePromptNotificationItem { + __typename + } + ... on ArticleFeaturedArtistNotificationItem { article { internalID } } } + ...ActivityRailItem_item } } diff --git a/src/app/Scenes/HomeView/Sections/HomeViewSectionActivity.tsx b/src/app/Scenes/HomeView/Sections/HomeViewSectionActivity.tsx index d1496ffdcb4..047dc0c94ca 100644 --- a/src/app/Scenes/HomeView/Sections/HomeViewSectionActivity.tsx +++ b/src/app/Scenes/HomeView/Sections/HomeViewSectionActivity.tsx @@ -39,8 +39,8 @@ export const HomeViewSectionActivity: React.FC = ( const tracking = useHomeViewTracking() const section = useFragment(sectionFragment, sectionProp) - const notifications = extractNodes(section.notificationsConnection).filter( - shouldDisplayNotification + const notifications = extractNodes(section.notificationsConnection).filter((notification) => + shouldDisplayNotification(notification, "rail") ) const viewAll = section.component?.behaviors?.viewAll @@ -134,6 +134,8 @@ const sectionFragment = graphql` } targetHref item { + __typename + ... on ViewingRoomPublishedNotificationItem { viewingRoomsConnection(first: 1) { totalCount