1- import React , { useEffect , useRef , useState } from 'react' ;
1+ import React from 'react' ;
22import Link from '../../utilities/Link' ;
33import EntityCard from './EntityCard' ;
44import {
@@ -13,23 +13,11 @@ import CustomFeedOptionsMenu from '../../CustomFeedOptionsMenu';
1313import { ButtonVariant } from '../../buttons/Button' ;
1414import { Separator } from '../common/common' ;
1515import EntityDescription from './EntityDescription' ;
16- import EnableNotificationsCta from './EnableNotificationsCta' ;
1716import useSourceMenuProps from '../../../hooks/useSourceMenuProps' ;
18- import {
19- ContentPreferenceStatus ,
20- ContentPreferenceType ,
21- } from '../../../graphql/contentPreference' ;
22- import {
23- NotificationCtaPlacement ,
24- NotificationPromptSource ,
25- TargetType ,
26- } from '../../../lib/log' ;
17+ import { ContentPreferenceType } from '../../../graphql/contentPreference' ;
2718import useShowFollowAction from '../../../hooks/useShowFollowAction' ;
2819import { FollowButton } from '../../contentPreference/FollowButton' ;
2920import { useContentPreferenceStatusQuery } from '../../../hooks/contentPreference/useContentPreferenceStatusQuery' ;
30- import { useContentPreference } from '../../../hooks/contentPreference/useContentPreference' ;
31- import { useSourceActionsNotify } from '../../../hooks/source/useSourceActionsNotify' ;
32- import { useNotificationCtaExperiment } from '../../../hooks/notifications/useNotificationCtaExperiment' ;
3321
3422type SourceEntityCardProps = {
3523 source : SourceTooltip ;
@@ -49,68 +37,12 @@ const SourceEntityCard = ({ source, className }: SourceEntityCardProps) => {
4937 id : sourceId ,
5038 entity : ContentPreferenceType . Source ,
5139 } ) ;
52- const [ showNotificationCta , setShowNotificationCta ] = useState ( false ) ;
53- const { isEnabled : isNotificationCtaExperimentEnabled } =
54- useNotificationCtaExperiment ( {
55- shouldEvaluate : showNotificationCta ,
56- } ) ;
57- const { subscribe } = useContentPreference ( ) ;
58- const prevStatusRef = useRef ( contentPreference ?. status ) ;
5940 const menuProps = useSourceMenuProps ( { source } ) ;
60- const { haveNotificationsOn, onNotify } = useSourceActionsNotify ( {
61- source,
62- } ) ;
63-
64- const currentStatus = contentPreference ?. status ;
65- const isNowFollowing =
66- currentStatus === ContentPreferenceStatus . Follow ||
67- currentStatus === ContentPreferenceStatus . Subscribed ;
68- const wasFollowing =
69- prevStatusRef . current === ContentPreferenceStatus . Follow ||
70- prevStatusRef . current === ContentPreferenceStatus . Subscribed ;
71- const shouldRenderNotificationCta =
72- isNotificationCtaExperimentEnabled &&
73- showNotificationCta &&
74- ! haveNotificationsOn ;
75-
76- useEffect ( ( ) => {
77- if ( currentStatus === prevStatusRef . current ) {
78- return ;
79- }
80-
81- prevStatusRef . current = currentStatus ;
82-
83- if ( isNowFollowing && ! wasFollowing ) {
84- setShowNotificationCta ( true ) ;
85- return ;
86- }
87-
88- if ( ! isNowFollowing && wasFollowing ) {
89- setShowNotificationCta ( false ) ;
90- }
91- } , [ currentStatus , isNowFollowing , wasFollowing ] ) ;
9241
9342 if ( ! source ?. id || ! source . name || ! source . image || ! source . permalink ) {
9443 return null ;
9544 }
9645
97- const handleTurnOn = async ( ) => {
98- if ( ! source ?. id ) {
99- throw new Error ( 'Cannot subscribe to notifications without source id' ) ;
100- }
101-
102- if ( currentStatus !== ContentPreferenceStatus . Subscribed ) {
103- await subscribe ( {
104- id : source . id ,
105- entity : ContentPreferenceType . Source ,
106- entityName : source . name ?? source . id ,
107- } ) ;
108- }
109-
110- await onNotify ( ) ;
111- setShowNotificationCta ( false ) ;
112- } ;
113-
11446 return (
11547 < EntityCard
11648 permalink = { source . permalink }
@@ -174,17 +106,6 @@ const SourceEntityCard = ({ source, className }: SourceEntityCardProps) => {
174106 { largeNumberFormat ( source . flags ?. totalUpvotes ?? 0 ) || 0 } Upvotes
175107 </ Typography >
176108 </ div >
177- { shouldRenderNotificationCta && (
178- < EnableNotificationsCta
179- onEnable = { handleTurnOn }
180- analytics = { {
181- placement : NotificationCtaPlacement . SourceCard ,
182- targetType : TargetType . Source ,
183- targetId : source . id ,
184- source : NotificationPromptSource . SourceSubscribe ,
185- } }
186- />
187- ) }
188109 </ div >
189110 </ EntityCard >
190111 ) ;
0 commit comments