diff --git a/web/components/action-buttons/NotifyButton.tsx b/web/components/action-buttons/NotifyButton.tsx index 5e0b709d4..13768c1f8 100644 --- a/web/components/action-buttons/NotifyButton.tsx +++ b/web/components/action-buttons/NotifyButton.tsx @@ -1,30 +1,20 @@ import { Button } from 'antd'; import { NotificationFilled } from '@ant-design/icons'; -import { useState } from 'react'; -import Modal from '../ui/Modal/Modal'; import s from './ActionButton.module.scss'; -import BrowserNotifyModal from '../modals/BrowserNotify/BrowserNotifyModal'; -export default function NotifyButton() { - const [showModal, setShowModal] = useState(false); - - const buttonClicked = () => { - setShowModal(true); - }; +interface Props { + onClick: () => void; +} +export default function NotifyButton({ onClick }: Props) { return ( - <> - - setShowModal(false)}> - - - + ); } diff --git a/web/components/ui/Content/Content.tsx b/web/components/ui/Content/Content.tsx index e4905aacb..a94a370e7 100644 --- a/web/components/ui/Content/Content.tsx +++ b/web/components/ui/Content/Content.tsx @@ -1,6 +1,9 @@ /* eslint-disable react/no-danger */ import { useRecoilValue } from 'recoil'; import { Layout, Tabs, Spin } from 'antd'; +import { useEffect, useState } from 'react'; +import { LOCAL_STORAGE_KEYS, getLocalStorage, setLocalStorage } from '../../../utils/localStorage'; + import { clientConfigStateAtom, chatMessagesAtom, @@ -34,6 +37,8 @@ import OfflineBanner from '../OfflineBanner/OfflineBanner'; import { AppStateOptions } from '../../stores/application-state'; import FollowButton from '../../action-buttons/FollowButton'; import NotifyButton from '../../action-buttons/NotifyButton'; +import Modal from '../Modal/Modal'; +import BrowserNotifyModal from '../../modals/BrowserNotify/BrowserNotifyModal'; const { TabPane } = Tabs; const { Content } = Layout; @@ -50,6 +55,8 @@ export default function ContentComponent() { const { extraPageContent, version, socialHandles, name, title, tags, summary } = clientConfig; const { viewerCount, lastConnectTime, lastDisconnectTime } = status; + const [showNotifyReminder, setShowNotifyReminder] = useState(false); + const [showNotifyPopup, setShowNotifyPopup] = useState(false); const followers: Follower[] = []; @@ -71,6 +78,29 @@ export default function ContentComponent() { )); + const incrementVisitCounter = () => { + let visits = parseInt(getLocalStorage(LOCAL_STORAGE_KEYS.userVisitCount), 10); + if (Number.isNaN(visits)) { + visits = 0; + } + + setLocalStorage(LOCAL_STORAGE_KEYS.userVisitCount, visits + 1); + + if (visits > 2 && !getLocalStorage(LOCAL_STORAGE_KEYS.hasDisplayedNotificationModal)) { + setShowNotifyReminder(true); + } + }; + + const disableNotifyReminderPopup = () => { + setShowNotifyPopup(false); + setShowNotifyReminder(false); + setLocalStorage(LOCAL_STORAGE_KEYS.hasDisplayedNotificationModal, true); + }; + + useEffect(() => { + incrementVisitCounter(); + }, []); + return ( @@ -95,14 +125,23 @@ export default function ContentComponent() { {externalActionButtons} {}} - notificationClosed={() => {}} + visible={showNotifyReminder} + notificationClicked={() => setShowNotifyPopup(true)} + notificationClosed={() => disableNotifyReminderPopup()} > - + setShowNotifyPopup(true)} /> + disableNotifyReminderPopup()} + handleCancel={() => disableNotifyReminderPopup()} + > + + +
diff --git a/web/components/ui/NotifyReminderPopup/NotifyReminderPopup.tsx b/web/components/ui/NotifyReminderPopup/NotifyReminderPopup.tsx index f6d9e356d..dcea5eb55 100644 --- a/web/components/ui/NotifyReminderPopup/NotifyReminderPopup.tsx +++ b/web/components/ui/NotifyReminderPopup/NotifyReminderPopup.tsx @@ -1,7 +1,6 @@ import { Popover } from 'antd'; import { CloseOutlined } from '@ant-design/icons'; import React, { useState, useEffect } from 'react'; -import { LOCAL_STORAGE_KEYS, getLocalStorage } from '../../../utils/localStorage'; import s from './NotifyReminderPopup.module.scss'; interface Props { @@ -15,11 +14,13 @@ export default function NotifyReminderPopup(props: Props) { const { children, visible, notificationClicked, notificationClosed } = props; const [visiblePopup, setVisiblePopup] = useState(visible); const [mounted, setMounted] = useState(false); - const [shouldShowPopup, setShouldShowPopup] = useState(false); + + useEffect(() => { + setVisiblePopup(visible); + }, [visible]); useEffect(() => { setMounted(true); - setShouldShowPopup(!getLocalStorage(LOCAL_STORAGE_KEYS.hasDisplayedNotificationModal)); }, []); const title =
Stay updated!
; @@ -43,20 +44,20 @@ export default function NotifyReminderPopup(props: Props) { }; const content = ( -
+
- +
); + return ( - mounted && - shouldShowPopup && ( + mounted && (