diff --git a/ghost/portal/src/actions.js b/ghost/portal/src/actions.js index a62d065f70..7abe689e7a 100644 --- a/ghost/portal/src/actions.js +++ b/ghost/portal/src/actions.js @@ -268,14 +268,21 @@ async function showPopupNotification({data, state}) { async function updateNewsletterPreference({data, state, api}) { try { - const {newsletters} = data; - if (!newsletters) { + const {newsletters, enableCommentNotifications} = data; + if (!newsletters && enableCommentNotifications === undefined) { return {}; } - const member = await api.member.update({newsletters}); + const updateData = {}; + if (newsletters) { + updateData.newsletters = newsletters; + } + if (enableCommentNotifications !== undefined) { + updateData.enableCommentNotifications = enableCommentNotifications; + } + const member = await api.member.update(updateData); const action = 'updateNewsletterPref:success'; return { - action, + action, member }; } catch (e) { diff --git a/ghost/portal/src/components/common/NewsletterManagement.js b/ghost/portal/src/components/common/NewsletterManagement.js index cf8f12c767..3051434e5a 100644 --- a/ghost/portal/src/components/common/NewsletterManagement.js +++ b/ghost/portal/src/components/common/NewsletterManagement.js @@ -85,6 +85,38 @@ function NewsletterPrefSection({newsletter, subscribedNewsletters, setSubscribed ); } +function CommentsSection({updateCommentNotifications, isCommentsEnabled, enableCommentNotifications}) { + const isChecked = !!enableCommentNotifications; + + const [showUpdated, setShowUpdated] = useState(false); + const [timeoutId, setTimeoutId] = useState(null); + + if (!isCommentsEnabled) { + return null; + } + + return ( +
+
+

Comments

+

Likes and replies to my comments

+
+
+ + { + setShowUpdated(true); + clearTimeout(timeoutId); + let newTimeoutId = setTimeout(() => { + setShowUpdated(false); + }, 2000); + setTimeoutId(newTimeoutId); + updateCommentNotifications(checked); + }} checked={isChecked} /> +
+
+ ); +} + function NewsletterPrefs({subscribedNewsletters, setSubscribedNewsletters}) { const {site} = useContext(AppContext); const newsletters = getSiteNewsletters({site}); @@ -113,11 +145,14 @@ export default function NewsletterManagement({ notification, subscribedNewsletters, updateSubscribedNewsletters, + updateCommentNotifications, unsubscribeAll, - isPaidMember + isPaidMember, + isCommentsEnabled, + enableCommentNotifications }) { - const isDisabled = !subscribedNewsletters?.length; const {brandColor, site} = useContext(AppContext); + const isDisabled = !subscribedNewsletters?.length && ((isCommentsEnabled && !enableCommentNotifications) || !isCommentsEnabled); const EmptyNotification = () => { return null; }; @@ -140,6 +175,11 @@ export default function NewsletterManagement({ updateSubscribedNewsletters(newsletters); }} /> +