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 React from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { ENABLE_UI_NOTIFICATIONS } from 'config';
|
import { ENABLE_UI_NOTIFICATIONS } from 'config';
|
||||||
|
import { buildUnseenCountStr } from 'util/notifications';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
unseenCount: number,
|
unseenCount: number,
|
||||||
|
@ -28,7 +29,7 @@ export default function NotificationHeaderButton(props: Props) {
|
||||||
'notification__bubble--small': unseenCount > 9,
|
'notification__bubble--small': unseenCount > 9,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{unseenCount > 20 ? '20+' : unseenCount}
|
{buildUnseenCountStr(unseenCount)}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { selectTitleForUri } from 'redux/selectors/claims';
|
||||||
import { doSetHasNavigated } from 'redux/actions/app';
|
import { doSetHasNavigated } from 'redux/actions/app';
|
||||||
import { doUserSetReferrer } from 'redux/actions/user';
|
import { doUserSetReferrer } from 'redux/actions/user';
|
||||||
import { selectHasUnclaimedRefereeReward } from 'redux/selectors/rewards';
|
import { selectHasUnclaimedRefereeReward } from 'redux/selectors/rewards';
|
||||||
|
import { selectUnseenNotificationCount } from 'redux/selectors/notifications';
|
||||||
|
|
||||||
const select = (state) => {
|
const select = (state) => {
|
||||||
const { pathname, hash } = state.router.location;
|
const { pathname, hash } = state.router.location;
|
||||||
|
@ -36,6 +37,7 @@ const select = (state) => {
|
||||||
hasUnclaimedRefereeReward: selectHasUnclaimedRefereeReward(state),
|
hasUnclaimedRefereeReward: selectHasUnclaimedRefereeReward(state),
|
||||||
homepageData: selectHomepageData(state),
|
homepageData: selectHomepageData(state),
|
||||||
wildWestDisabled: selectWildWestDisabled(state),
|
wildWestDisabled: selectWildWestDisabled(state),
|
||||||
|
unseenCount: selectUnseenNotificationCount(state),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { SITE_TITLE, WELCOME_VERSION } from 'config';
|
||||||
import LoadingBarOneOff from 'component/loadingBarOneOff';
|
import LoadingBarOneOff from 'component/loadingBarOneOff';
|
||||||
import { GetLinksData } from 'util/buildHomepage';
|
import { GetLinksData } from 'util/buildHomepage';
|
||||||
import * as CS from 'constants/claim_search';
|
import * as CS from 'constants/claim_search';
|
||||||
|
import { buildUnseenCountStr } from 'util/notifications';
|
||||||
|
|
||||||
import HomePage from 'page/home';
|
import HomePage from 'page/home';
|
||||||
|
|
||||||
|
@ -138,6 +139,7 @@ type Props = {
|
||||||
hasUnclaimedRefereeReward: boolean,
|
hasUnclaimedRefereeReward: boolean,
|
||||||
homepageData: any,
|
homepageData: any,
|
||||||
wildWestDisabled: boolean,
|
wildWestDisabled: boolean,
|
||||||
|
unseenCount: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
type PrivateRouteProps = Props & {
|
type PrivateRouteProps = Props & {
|
||||||
|
@ -178,6 +180,7 @@ function AppRouter(props: Props) {
|
||||||
setReferrer,
|
setReferrer,
|
||||||
homepageData,
|
homepageData,
|
||||||
wildWestDisabled,
|
wildWestDisabled,
|
||||||
|
unseenCount,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const { entries, listen, action: historyAction } = history;
|
const { entries, listen, action: historyAction } = history;
|
||||||
|
@ -246,10 +249,10 @@ function AppRouter(props: Props) {
|
||||||
document.title = getDefaultTitle(pathname);
|
document.title = getDefaultTitle(pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @if TARGET='app'
|
if (unseenCount > 0) {
|
||||||
entries[entryIndex].title = document.title;
|
document.title = `(${buildUnseenCountStr(unseenCount)}) ${document.title}`;
|
||||||
// @endif
|
}
|
||||||
}, [pathname, entries, entryIndex, title, uri]);
|
}, [pathname, entries, entryIndex, title, uri, unseenCount]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasLinkedCommentInUrl) {
|
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