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
4 changes: 2 additions & 2 deletions src/learning-header/AuthenticatedUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -36,7 +36,7 @@ const AuthenticatedUser = ({
showTray,
isNewNotificationView,
notificationAppData,
} = useNotification();
} = useAppNotifications();

if (isNewNotificationView) {
return (
Expand Down
30 changes: 18 additions & 12 deletions src/new-notifications/data/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Loading