diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -23,7 +23,6 @@ createLoadingStatusSelector, combineLoadingStatuses, } from 'lib/selectors/loading-selectors.js'; -import { unreadCount } from 'lib/selectors/thread-selectors.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import type { LoadingStatus } from 'lib/types/loading-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; @@ -42,6 +41,7 @@ import UpdateModalHandler from './modals/update-modal.react.js'; import SettingsSwitcher from './navigation-panels/settings-switcher.react.js'; import Topbar from './navigation-panels/topbar.react.js'; +import useBadgeHandler from './push-notif/badge-handler.react.js'; import { PushNotificationsHandler } from './push-notif/push-notifs-handler.js'; import { updateNavInfoActionType } from './redux/action-types.js'; import DeviceIDUpdater from './redux/device-id-updater.js'; @@ -58,7 +58,6 @@ import Splash from './splash/splash.react.js'; import './typography.css'; import css from './style.css'; -import getTitle from './title/getTitle.js'; import { type NavInfo } from './types/nav-types.js'; import { canonicalURLFromReduxState, navInfoFromURL } from './url-utils.js'; @@ -309,11 +308,7 @@ !!state.threadStore.threadInfos[activeChatThreadID]?.currentUser.unread, ); - const boundUnreadCount = useSelector(unreadCount); - React.useEffect(() => { - document.title = getTitle(boundUnreadCount); - electron?.setBadge(boundUnreadCount === 0 ? null : boundUnreadCount); - }, [boundUnreadCount]); + useBadgeHandler(); const dispatch = useDispatch(); const modalContext = useModalContext(); diff --git a/web/push-notif/badge-handler.react.js b/web/push-notif/badge-handler.react.js new file mode 100644 --- /dev/null +++ b/web/push-notif/badge-handler.react.js @@ -0,0 +1,20 @@ +// @flow + +import * as React from 'react'; +import { useSelector } from 'react-redux'; + +import { unreadCount } from 'lib/selectors/thread-selectors.js'; + +import electron from '../electron.js'; +import getTitle from '../title/getTitle.js'; + +function useBadgeHandler() { + const boundUnreadCount = useSelector(unreadCount); + + React.useEffect(() => { + document.title = getTitle(boundUnreadCount); + electron?.setBadge(boundUnreadCount === 0 ? null : boundUnreadCount); + }, [boundUnreadCount]); +} + +export default useBadgeHandler;