diff --git a/src/learning-header/AuthenticatedUser.jsx b/src/learning-header/AuthenticatedUser.jsx index 3c48c615..be797485 100644 --- a/src/learning-header/AuthenticatedUser.jsx +++ b/src/learning-header/AuthenticatedUser.jsx @@ -8,7 +8,7 @@ import { AppContext } from '@edx/frontend-platform/react'; import AuthenticatedUserDropdown from './AuthenticatedUserDropdown'; import NewAuthenticatedUserDropdown from './New-AuthenticatedUserDropdown'; import messages from './messages'; -import { useNotification } from '../new-notifications/data/hook'; +import { useAppNotifications } from '../new-notifications/data/hook'; import Notifications from '../new-notifications'; const BaseAuthenticatedUser = ({ children }) => { @@ -36,7 +36,7 @@ const AuthenticatedUser = ({ showTray, isNewNotificationView, notificationAppData, - } = useNotification(); + } = useAppNotifications(); if (isNewNotificationView) { return ( diff --git a/src/new-notifications/data/hook.js b/src/new-notifications/data/hook.js index 9c8b5637..72645955 100644 --- a/src/new-notifications/data/hook.js +++ b/src/new-notifications/data/hook.js @@ -27,11 +27,6 @@ export function useNotification() { const { appName, apps, tabsCount, notifications, updateNotificationData, } = useContext(notificationsContext); - const { authenticatedUser } = useContext(AppContext); - const [showTray, setShowTray] = useState(); - const [isNewNotificationView, setIsNewNotificationView] = useState(false); - const [notificationAppData, setNotificationAppData] = useState(); - const location = useLocation(); const normalizeNotificationCounts = useCallback(({ countByAppName, ...countData }) => { const appIds = Object.keys(countByAppName); @@ -170,6 +165,24 @@ export function useNotification() { } }, [notifications]); + return { + fetchAppsNotificationCount, + fetchNotificationList, + getNotifications, + markNotificationsAsSeen, + markAllNotificationsAsRead, + markNotificationsAsRead, + }; +} + +export function useAppNotifications() { + const { authenticatedUser } = useContext(AppContext); + const [showTray, setShowTray] = useState(); + const [isNewNotificationView, setIsNewNotificationView] = useState(false); + const [notificationAppData, setNotificationAppData] = useState(); + const { fetchAppsNotificationCount } = useNotification(); + const location = useLocation(); + const fetchNotificationData = useCallback(async () => { const data = await fetchAppsNotificationCount(); const { showNotificationsTray, isNewNotificationViewEnabled } = data; @@ -183,19 +196,12 @@ export function useNotification() { const fetchNotifications = async () => { await fetchNotificationData(); }; - // Only fetch notifications when user is authenticated if (authenticatedUser) { fetchNotifications(); } }, [fetchNotificationData, authenticatedUser, location.pathname]); return { - fetchAppsNotificationCount, - fetchNotificationList, - getNotifications, - markNotificationsAsSeen, - markAllNotificationsAsRead, - markNotificationsAsRead, showTray, isNewNotificationView, notificationAppData,