Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion client/dashboard/app/interim-omnibar/interim-omnibar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MasterbarLoggedIn } from 'calypso/layout/masterbar/logged-in';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { getSiteDisplayName } from '../../utils/site-name';
import { logout } from '../auth';
import { omnibarEvents } from './omnibar-events';
import { omnibarEvents, useOmnibarEvent } from './omnibar-events';
import { createOmnibarStore } from './omnibar-store';
import type { User, Site } from '@automattic/api-core';

Expand Down Expand Up @@ -57,6 +57,19 @@ export function InterimOmnibar( {
omnibarEvents.notificationsAnchor.emit( bell );
} );

// Dispatch the user's unseen note count to the store so the unread marker appears.
useEffect( () => {
store.dispatch( {
type: 'NOTIFICATIONS_UNSEEN_COUNT_SET',
unseenCount: Number( !! user.has_unseen_notes ),
} );
}, [ store, user.has_unseen_notes ] );

// Also dispatch the emitted unseen note count from the notifications panel.
useOmnibarEvent( 'notificationsUnseenCount', ( unseenCount ) => {
store.dispatch( { type: 'NOTIFICATIONS_UNSEEN_COUNT_SET', unseenCount } );
} );

return (
<QueryClientProvider client={ omnibarQueryClient }>
<ReduxProvider store={ store }>
Expand Down
1 change: 1 addition & 0 deletions client/dashboard/app/interim-omnibar/omnibar-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const omnibarEvents = {
mobileMenu: createOmnibarEvent(),
notificationsAnchor: createOmnibarEvent< HTMLElement | null >(),
notifications: createOmnibarEvent(),
notificationsUnseenCount: createOmnibarEvent< number >(),
linkClick: createOmnibarEvent< { href: string; event: MouseEvent } >(),
};

Expand Down
22 changes: 19 additions & 3 deletions client/dashboard/app/interim-omnibar/omnibar-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@ type StoreType = Parameters< typeof ReduxProvider >[ 0 ][ 'store' ];
// Fake Redux store so child components using connect() (e.g. Notifications) don't crash.
// Intercepts specific actions so the dashboard can handle them.
export function createOmnibarStore( onToggleNotifications?: () => void ): StoreType {
const listeners = new Set< () => void >();
let notificationsUnseenCount: number | undefined;

return {
getState: () => ( { ui: { section: false, isNotificationsOpen: false } } ),
dispatch: ( action: { type: string } ) => {
getState: () => ( {
ui: { section: false, isNotificationsOpen: false },
notificationsUnseenCount,
} ),
dispatch: ( action: { type: string; unseenCount?: number } ) => {
if ( action.type === 'NOTIFICATIONS_PANEL_TOGGLE' ) {
onToggleNotifications?.();

notificationsUnseenCount = 0;
listeners.forEach( ( listener ) => listener() );
}
if ( action.type === 'NOTIFICATIONS_UNSEEN_COUNT_SET' ) {
notificationsUnseenCount = action.unseenCount;
listeners.forEach( ( listener ) => listener() );
}
return action;
},
subscribe: () => () => {},
subscribe: ( listener: () => void ) => {
listeners.add( listener );
return () => listeners.delete( listener );
},
} as unknown as StoreType;
}
3 changes: 2 additions & 1 deletion client/dashboard/app/notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Suspense, lazy, useCallback, useEffect, useState } from 'react';
import wpcom from 'calypso/lib/wp';
import { useAuth } from '../auth';
import { useHelpCenter } from '../help-center';
import { useOmnibarEvent } from '../interim-omnibar/omnibar-events';
import { omnibarEvents, useOmnibarEvent } from '../interim-omnibar/omnibar-events';
import { useLocale } from '../locale';
import './style.scss';

Expand Down Expand Up @@ -54,6 +54,7 @@ export default function Notifications( {
APP_RENDER_NOTES: [
( store: unknown, { newNoteCount }: { newNoteCount: number } ) => {
setHasUnseenNotifications( newNoteCount > 0 );
omnibarEvents.notificationsUnseenCount.emit( newNoteCount );
},
],
VIEW_SETTINGS: [
Expand Down
Loading