123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- "use strict";
- exports.id = 39953;
- exports.ids = [39953];
- exports.modules = {
- /***/ 39953:
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
- /* harmony export */ "Bh": () => (/* binding */ setNotificationsLoading),
- /* harmony export */ "Qw": () => (/* binding */ setUnseenCount),
- /* harmony export */ "ZP": () => (__WEBPACK_DEFAULT_EXPORT__),
- /* harmony export */ "dq": () => (/* binding */ selectLoadedNotificationsPages),
- /* harmony export */ "gC": () => (/* binding */ setNotificationsPageAndFinishLoading),
- /* harmony export */ "mv": () => (/* binding */ selectNotificationsIsFetching)
- /* harmony export */ });
- /* unused harmony exports notificationsSlice, setAllAsRead, setNotificationAsRead, setDeleteNotification, selectUnseenCount, selectNotifications, selectHasMoreNotifications, selectLastLoadedNotificationsPage, selectNotificationsIsLoading */
- /* harmony import */ var _reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(75184);
- /* harmony import */ var _reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__);
- /* harmony import */ var _defaultSettings_util__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(17241);
- /* harmony import */ var _redux_types_SliceName__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(61243);
- /* eslint-disable max-lines */
- // A helper function to clone and process the notifications while keeping the pagination intact.
- const cloneAndProcessNotifications = (state, processor)=>{
- const newPagedNotifications = {};
- const newNotifications = [];
- Object.keys(state.paginatedNotifications).forEach((pageKey)=>{
- const old = {
- ...state.paginatedNotifications[pageKey],
- data: [
- ...state.paginatedNotifications[pageKey].data
- ]
- };
- const newData = processor(old.data);
- newPagedNotifications[pageKey] = {
- ...old,
- data: newData
- };
- newNotifications.push(...newData);
- });
- return {
- notifications: newNotifications,
- paginatedNotifications: newPagedNotifications
- };
- };
- const notificationsSlice = (0,_reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__.createSlice)({
- name: _redux_types_SliceName__WEBPACK_IMPORTED_MODULE_2__/* ["default"].NOTIFICATIONS */ .Z.NOTIFICATIONS,
- initialState: (0,_defaultSettings_util__WEBPACK_IMPORTED_MODULE_1__/* .getNotificationsInitialState */ .$t)(),
- reducers: {
- setNotificationsLoading: (state, action)=>({
- ...state,
- isLoadingNotifications: action.payload.isLoading,
- isFetchingNotifications: action.payload.isFetching,
- /**
- * reset the notifications if the flag is set to true
- * this is useful when we want to fetch the data from the beginning when the user re-opens the notification widget
- */ ...action.payload.shouldResetOldData ? {
- notifications: [],
- paginatedNotifications: {}
- } : {}
- }),
- setNotificationsPageAndFinishLoading: (state, action)=>{
- const newPagedNotifications = {
- ...action.payload.shouldResetOldData ? {} : state.paginatedNotifications,
- [action.payload.page]: action.payload.data
- };
- // eslint-disable-next-line unicorn/no-array-reduce
- const newNotifications = Object.keys(newPagedNotifications).reduce((acc, pageKey)=>{
- return [
- ...acc,
- ...newPagedNotifications[pageKey].data
- ];
- }, []);
- return {
- ...state,
- paginatedNotifications: newPagedNotifications,
- notifications: newNotifications,
- isLoadingNotifications: false,
- isFetchingNotifications: false
- };
- },
- setUnseenCount: (state, action)=>({
- ...state,
- unseenCount: action.payload
- }),
- setAllAsRead: (state)=>{
- return {
- ...state,
- ...cloneAndProcessNotifications(state, (notifications)=>notifications.map((notification)=>({
- ...notification,
- read: true
- })))
- };
- },
- setNotificationAsRead: (state, action)=>{
- return {
- ...state,
- ...cloneAndProcessNotifications(state, (notifications)=>notifications.map((notification)=>{
- // eslint-disable-next-line no-underscore-dangle
- if (notification._id === action.payload.messageId) {
- return {
- ...notification,
- read: true
- };
- }
- return notification;
- }))
- };
- },
- setDeleteNotification: (state, action)=>{
- return {
- ...state,
- ...cloneAndProcessNotifications(state, (notifications)=>notifications.filter((notification)=>{
- // eslint-disable-next-line no-underscore-dangle
- return notification._id !== action.payload.messageId;
- }))
- };
- }
- }
- });
- const { setNotificationsLoading , setNotificationsPageAndFinishLoading , setUnseenCount , setAllAsRead , setNotificationAsRead , setDeleteNotification , } = notificationsSlice.actions;
- const selectUnseenCount = (state)=>state.notifications.unseenCount;
- const selectNotifications = (state)=>state.notifications.notifications;
- const selectHasMoreNotifications = (state)=>{
- const { paginatedNotifications } = state.notifications;
- const lastPage = Math.max(...Object.keys(paginatedNotifications));
- return !!paginatedNotifications[lastPage]?.hasMore;
- };
- const selectLastLoadedNotificationsPage = (state)=>{
- const { paginatedNotifications } = state.notifications;
- return Math.max(...Object.keys(paginatedNotifications));
- };
- const selectLoadedNotificationsPages = (state)=>{
- const { paginatedNotifications } = state.notifications;
- return Object.keys(paginatedNotifications);
- };
- const selectNotificationsIsLoading = (state)=>state.notifications.isLoadingNotifications;
- const selectNotificationsIsFetching = (state)=>state.notifications.isFetchingNotifications;
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (notificationsSlice.reducer);
- /***/ })
- };
- ;
- //# sourceMappingURL=39953.js.map
|