Update browser window title when notifications are received
This commit is contained in:
parent
2e8039c3d0
commit
4cec3ee9b3
4 changed files with 14 additions and 5 deletions
|
@ -2,6 +2,7 @@
|
|||
import React from 'react';
|
||||
import classnames from 'classnames';
|
||||
import { ENABLE_UI_NOTIFICATIONS } from 'config';
|
||||
import { buildUnseenCountStr } from 'util/notifications';
|
||||
|
||||
type Props = {
|
||||
unseenCount: number,
|
||||
|
@ -28,7 +29,7 @@ export default function NotificationHeaderButton(props: Props) {
|
|||
'notification__bubble--small': unseenCount > 9,
|
||||
})}
|
||||
>
|
||||
{unseenCount > 20 ? '20+' : unseenCount}
|
||||
{buildUnseenCountStr(unseenCount)}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
|
|
|
@ -8,6 +8,7 @@ import { selectTitleForUri } from 'redux/selectors/claims';
|
|||
import { doSetHasNavigated } from 'redux/actions/app';
|
||||
import { doUserSetReferrer } from 'redux/actions/user';
|
||||
import { selectHasUnclaimedRefereeReward } from 'redux/selectors/rewards';
|
||||
import { selectUnseenNotificationCount } from 'redux/selectors/notifications';
|
||||
|
||||
const select = (state) => {
|
||||
const { pathname, hash } = state.router.location;
|
||||
|
@ -36,6 +37,7 @@ const select = (state) => {
|
|||
hasUnclaimedRefereeReward: selectHasUnclaimedRefereeReward(state),
|
||||
homepageData: selectHomepageData(state),
|
||||
wildWestDisabled: selectWildWestDisabled(state),
|
||||
unseenCount: selectUnseenNotificationCount(state),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import { SITE_TITLE, WELCOME_VERSION } from 'config';
|
|||
import LoadingBarOneOff from 'component/loadingBarOneOff';
|
||||
import { GetLinksData } from 'util/buildHomepage';
|
||||
import * as CS from 'constants/claim_search';
|
||||
import { buildUnseenCountStr } from 'util/notifications';
|
||||
|
||||
import HomePage from 'page/home';
|
||||
|
||||
|
@ -138,6 +139,7 @@ type Props = {
|
|||
hasUnclaimedRefereeReward: boolean,
|
||||
homepageData: any,
|
||||
wildWestDisabled: boolean,
|
||||
unseenCount: number,
|
||||
};
|
||||
|
||||
type PrivateRouteProps = Props & {
|
||||
|
@ -178,6 +180,7 @@ function AppRouter(props: Props) {
|
|||
setReferrer,
|
||||
homepageData,
|
||||
wildWestDisabled,
|
||||
unseenCount,
|
||||
} = props;
|
||||
|
||||
const { entries, listen, action: historyAction } = history;
|
||||
|
@ -246,10 +249,10 @@ function AppRouter(props: Props) {
|
|||
document.title = getDefaultTitle(pathname);
|
||||
}
|
||||
|
||||
// @if TARGET='app'
|
||||
entries[entryIndex].title = document.title;
|
||||
// @endif
|
||||
}, [pathname, entries, entryIndex, title, uri]);
|
||||
if (unseenCount > 0) {
|
||||
document.title = `(${buildUnseenCountStr(unseenCount)}) ${document.title}`;
|
||||
}
|
||||
}, [pathname, entries, entryIndex, title, uri, unseenCount]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasLinkedCommentInUrl) {
|
||||
|
|
3
ui/util/notifications.js
Normal file
3
ui/util/notifications.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
// @flow
|
||||
|
||||
export const buildUnseenCountStr = (unseenCount: number) => (unseenCount > 20 ? '20+' : `${unseenCount}`);
|
Loading…
Reference in a new issue