Skip to content

Commit

Permalink
refactor: moved pagination to normalised data
Browse files Browse the repository at this point in the history
  • Loading branch information
ayesha-waris committed Jul 7, 2023
1 parent e44e18c commit 36804f2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Notifications/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ const normalizeNotificationCounts = ({ countByAppName, count, showNotificationsT
};
};

const normalizeNotifications = (notifications) => {
const newNotificationIds = notifications.map(notification => notification.id.toString());
const notificationsKeyValuePair = notifications.reduce((acc, obj) => { acc[obj.id] = obj; return acc; }, {});
const normalizeNotifications = (data) => {
const newNotificationIds = data.results.map(notification => notification.id.toString());
const notificationsKeyValuePair = data.results.reduce((acc, obj) => { acc[obj.id] = obj; return acc; }, {});
const pagination = {
numPages: data.num_pages,
currentPage: data.current_page,
hasMorePages: !!data.next,
};
return {
newNotificationIds, notificationsKeyValuePair,
newNotificationIds, notificationsKeyValuePair, pagination,
};
};

Expand All @@ -48,13 +53,8 @@ export const fetchNotificationList = ({ appName, page }) => (
try {
dispatch(fetchNotificationRequest({ appName }));
const data = await getNotificationsList(appName, page);
const normalisedData = normalizeNotifications((camelCaseObject(data.results)));
const pagination = {
numPages: data.num_pages,
currentPage: data.current_page,
hasMorePages: !!data.next,
};
dispatch(fetchNotificationSuccess({ ...normalisedData, pagination }));
const normalisedData = normalizeNotifications((camelCaseObject(data)));
dispatch(fetchNotificationSuccess({ ...normalisedData }));
} catch (error) {
if (getHttpErrorStatus(error) === 403) {
dispatch(fetchNotificationDenied(appName));
Expand Down

0 comments on commit 36804f2

Please sign in to comment.