diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -23,13 +23,13 @@ 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'; import { registerConfig } from 'lib/utils/config.js'; import { WagmiENSCacheProvider, wagmiClient } from 'lib/utils/wagmi-utils.js'; +import useBadgeHandler from './badge-handler.react.js'; import Calendar from './calendar/calendar.react.js'; import Chat from './chat/chat.react.js'; import { TooltipProvider } from './chat/tooltip-provider.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/badge-handler.react.js b/web/badge-handler.react.js new file mode 100644 --- /dev/null +++ b/web/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;