Skip to content

Commit f21e818

Browse files
authored
Merge pull request #423 from rvsia/fixNotificaionCounter
Fix notificiation counter on first render
2 parents 9adc522 + 8ed4e8d commit f21e818

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/react-renderer-demo/src/app/src/components/layout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import ConnectedLinks from './common/connected-links';
2121
import Footer from './footer';
2222

2323
import dynamic from 'next/dynamic';
24-
import NotificationPanel, { lastMessageId } from './notification-panel';
24+
import NotificationPanel, { lastMessageId, oldestMessageId } from './notification-panel';
2525
const DocSearch = dynamic(import('./docsearch'), {
2626
ssr: false
2727
});
@@ -126,7 +126,7 @@ const Layout = ({ children }) => {
126126
const searchRef = useRef(null);
127127
const anchorRef = useRef(null);
128128
const [openNotification, setOpenNotifiation] = useState(false);
129-
const [lastCheck, setLastCheck] = useState('');
129+
const [lastCheck, setLastCheck] = useState(lastMessageId);
130130

131131
useEffect(() => {
132132
setLinks(findConnectedLinks(router.asPath, flatSchema) || {});
@@ -189,7 +189,7 @@ const Layout = ({ children }) => {
189189
>
190190
<DocSearch />
191191
<IconButton aria-label="show new notifications" onClick={handleToggle} color="inherit" ref={anchorRef} className={clsx(classes.menuButton)}>
192-
<Badge badgeContent={lastMessageId - lastCheck} color="secondary">
192+
<Badge badgeContent={lastMessageId - Math.max(lastCheck, oldestMessageId)} color="secondary">
193193
<NotificationsIcon className={classes.menuIcons} />
194194
</Badge>
195195
</IconButton>

packages/react-renderer-demo/src/app/src/components/notification-panel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const messageList = [
3535
];
3636

3737
export const lastMessageId = messageList[0].id;
38+
export const oldestMessageId = messageList[messageList.length - 1].id - 1;
3839

3940
const useStyles = makeStyles((theme) => ({
4041
paper: {

0 commit comments

Comments
 (0)