refactor: fixed code refactor and added new slices and selector
This commit is contained in:
@@ -1,9 +1,23 @@
|
||||
export const getNotificationStatus = () => state => state.notifications.notificationStatus;
|
||||
export const getNotificationTabsCount = () => state => state.notifications.tabsCount;
|
||||
export const getNotificationTabs = () => state => state.notifications.appsId;
|
||||
export const getSelectedAppNotificationIds = (appName) => state => state.notifications.apps[appName] ?? [];
|
||||
export const getNotificationTrayStatus = () => state => state.notifications.showNotificationTray;
|
||||
export const getNotificationsByIds = (notificationIds) => state => Object.entries(state.notifications.notifications)
|
||||
.filter(([key]) => notificationIds.includes(key)).map(([, value]) => value);
|
||||
export const getSelectedAppName = () => state => state.notifications.appName;
|
||||
export const getPaginationData = () => state => state.notifications.pagination;
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
export const selectNotificationStatus = () => state => state.notifications.notificationStatus;
|
||||
|
||||
export const selectNotificationTabsCount = () => state => state.notifications.tabsCount;
|
||||
|
||||
export const selectNotificationTabs = () => state => state.notifications.appsId;
|
||||
|
||||
export const selectSelectedAppNotificationIds = (appName) => state => state.notifications.apps[appName] ?? [];
|
||||
|
||||
export const selectShowNotificationTray = () => state => state.notifications.showNotificationTray;
|
||||
|
||||
export const selectNotifications = () => state => state.notifications.notification;
|
||||
|
||||
export const selectNotificationsByIds = createSelector(
|
||||
state => state.notifications.notifications,
|
||||
state => state.notifications.apps[state.notifications.appName] || [],
|
||||
(notifications, notificationIds) => notificationIds.map(notificationId => notifications[notificationId]),
|
||||
);
|
||||
|
||||
export const selectSelectedAppName = () => state => state.notifications.appName;
|
||||
|
||||
export const selectPaginationData = () => state => state.notifications.pagination;
|
||||
|
||||
@@ -19,6 +19,7 @@ const initialState = {
|
||||
count: 10,
|
||||
numPages: 1,
|
||||
currentPage: 1,
|
||||
nextPage: null,
|
||||
},
|
||||
};
|
||||
const slice = createSlice({
|
||||
@@ -115,6 +116,15 @@ 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;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -140,6 +150,8 @@ export const {
|
||||
markNotificationsAsReadSuccess,
|
||||
markNotificationsAsReadFailure,
|
||||
resetNotificationStateRequest,
|
||||
updateAppNameRequest,
|
||||
updatePaginationRequest,
|
||||
} = slice.actions;
|
||||
|
||||
export const notificationsReducer = slice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user