Skip to content

Commit

Permalink
fix: fixed count api recalling issue (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 authored Oct 25, 2024
1 parent 6a1d2c2 commit e7ec889
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
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

0 comments on commit e7ec889

Please sign in to comment.