refactor: removed backend api calls

This commit is contained in:
SundasNoreen
2023-06-08 20:57:14 +05:00
parent 784e9afccf
commit a211547a1d
4 changed files with 12 additions and 16 deletions

View File

@@ -1,11 +1,6 @@
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
import { camelCaseObject } from '@edx/frontend-platform';
import notificationsList from './notifications.json';
export const getNotificationsCountApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/count/`;
export const getNotificationsApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/`;
export const markNotificationsSeenApiUrl = (appName) => `${getConfig().LMS_BASE_URL}/api/notifications/mark-notifications-unseen/${appName}/`;
export async function getNotifications(appName, page, pageSize) {
const { data } = notificationsList;
const startIndex = (page - 1) * pageSize;
@@ -24,7 +19,7 @@ export async function getNotificationCounts() {
grades: 10,
authoring: 5,
},
show_notification_tray: true,
show_notification_tray: false,
};
return camelCaseObject(data);
}

View File

@@ -87,11 +87,11 @@ const slice = createSlice({
state.notificationStatus = LOADING;
},
markAllNotificationsAsReadSuccess: (state) => {
const date = new Date().toISOString();
const updatedNotifications = Object.entries(state.notifications)
.filter(([key]) => state.apps[state.appName].includes(key))
.map(([, value]) => ({ ...value, lastRead: date }));
const updatedNotifications = Object.fromEntries(
Object.entries(state.notifications).map(([key, notification]) => [
key, { ...notification, lastRead: new Date().toISOString() },
]),
);
state.notifications = updatedNotifications;
state.notificationStatus = LOADED;
},
@@ -116,12 +116,10 @@ const slice = createSlice({
state.notificationStatus = FAILED;
},
resetNotificationStateRequest: () => initialState,
updateAppNameRequest: (state, { payload }) => {
state.appName = payload.appName;
state.pagination.currentPage = 1;
},
updatePaginationRequest: (state) => {
state.pagination.currentPage += 1;
},