39953.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. "use strict";
  2. exports.id = 39953;
  3. exports.ids = [39953];
  4. exports.modules = {
  5. /***/ 39953:
  6. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  7. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  8. /* harmony export */ "Bh": () => (/* binding */ setNotificationsLoading),
  9. /* harmony export */ "Qw": () => (/* binding */ setUnseenCount),
  10. /* harmony export */ "ZP": () => (__WEBPACK_DEFAULT_EXPORT__),
  11. /* harmony export */ "dq": () => (/* binding */ selectLoadedNotificationsPages),
  12. /* harmony export */ "gC": () => (/* binding */ setNotificationsPageAndFinishLoading),
  13. /* harmony export */ "mv": () => (/* binding */ selectNotificationsIsFetching)
  14. /* harmony export */ });
  15. /* unused harmony exports notificationsSlice, setAllAsRead, setNotificationAsRead, setDeleteNotification, selectUnseenCount, selectNotifications, selectHasMoreNotifications, selectLastLoadedNotificationsPage, selectNotificationsIsLoading */
  16. /* harmony import */ var _reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(75184);
  17. /* harmony import */ var _reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__);
  18. /* harmony import */ var _defaultSettings_util__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(17241);
  19. /* harmony import */ var _redux_types_SliceName__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(61243);
  20. /* eslint-disable max-lines */
  21. // A helper function to clone and process the notifications while keeping the pagination intact.
  22. const cloneAndProcessNotifications = (state, processor)=>{
  23. const newPagedNotifications = {};
  24. const newNotifications = [];
  25. Object.keys(state.paginatedNotifications).forEach((pageKey)=>{
  26. const old = {
  27. ...state.paginatedNotifications[pageKey],
  28. data: [
  29. ...state.paginatedNotifications[pageKey].data
  30. ]
  31. };
  32. const newData = processor(old.data);
  33. newPagedNotifications[pageKey] = {
  34. ...old,
  35. data: newData
  36. };
  37. newNotifications.push(...newData);
  38. });
  39. return {
  40. notifications: newNotifications,
  41. paginatedNotifications: newPagedNotifications
  42. };
  43. };
  44. const notificationsSlice = (0,_reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__.createSlice)({
  45. name: _redux_types_SliceName__WEBPACK_IMPORTED_MODULE_2__/* ["default"].NOTIFICATIONS */ .Z.NOTIFICATIONS,
  46. initialState: (0,_defaultSettings_util__WEBPACK_IMPORTED_MODULE_1__/* .getNotificationsInitialState */ .$t)(),
  47. reducers: {
  48. setNotificationsLoading: (state, action)=>({
  49. ...state,
  50. isLoadingNotifications: action.payload.isLoading,
  51. isFetchingNotifications: action.payload.isFetching,
  52. /**
  53. * reset the notifications if the flag is set to true
  54. * this is useful when we want to fetch the data from the beginning when the user re-opens the notification widget
  55. */ ...action.payload.shouldResetOldData ? {
  56. notifications: [],
  57. paginatedNotifications: {}
  58. } : {}
  59. }),
  60. setNotificationsPageAndFinishLoading: (state, action)=>{
  61. const newPagedNotifications = {
  62. ...action.payload.shouldResetOldData ? {} : state.paginatedNotifications,
  63. [action.payload.page]: action.payload.data
  64. };
  65. // eslint-disable-next-line unicorn/no-array-reduce
  66. const newNotifications = Object.keys(newPagedNotifications).reduce((acc, pageKey)=>{
  67. return [
  68. ...acc,
  69. ...newPagedNotifications[pageKey].data
  70. ];
  71. }, []);
  72. return {
  73. ...state,
  74. paginatedNotifications: newPagedNotifications,
  75. notifications: newNotifications,
  76. isLoadingNotifications: false,
  77. isFetchingNotifications: false
  78. };
  79. },
  80. setUnseenCount: (state, action)=>({
  81. ...state,
  82. unseenCount: action.payload
  83. }),
  84. setAllAsRead: (state)=>{
  85. return {
  86. ...state,
  87. ...cloneAndProcessNotifications(state, (notifications)=>notifications.map((notification)=>({
  88. ...notification,
  89. read: true
  90. })))
  91. };
  92. },
  93. setNotificationAsRead: (state, action)=>{
  94. return {
  95. ...state,
  96. ...cloneAndProcessNotifications(state, (notifications)=>notifications.map((notification)=>{
  97. // eslint-disable-next-line no-underscore-dangle
  98. if (notification._id === action.payload.messageId) {
  99. return {
  100. ...notification,
  101. read: true
  102. };
  103. }
  104. return notification;
  105. }))
  106. };
  107. },
  108. setDeleteNotification: (state, action)=>{
  109. return {
  110. ...state,
  111. ...cloneAndProcessNotifications(state, (notifications)=>notifications.filter((notification)=>{
  112. // eslint-disable-next-line no-underscore-dangle
  113. return notification._id !== action.payload.messageId;
  114. }))
  115. };
  116. }
  117. }
  118. });
  119. const { setNotificationsLoading , setNotificationsPageAndFinishLoading , setUnseenCount , setAllAsRead , setNotificationAsRead , setDeleteNotification , } = notificationsSlice.actions;
  120. const selectUnseenCount = (state)=>state.notifications.unseenCount;
  121. const selectNotifications = (state)=>state.notifications.notifications;
  122. const selectHasMoreNotifications = (state)=>{
  123. const { paginatedNotifications } = state.notifications;
  124. const lastPage = Math.max(...Object.keys(paginatedNotifications));
  125. return !!paginatedNotifications[lastPage]?.hasMore;
  126. };
  127. const selectLastLoadedNotificationsPage = (state)=>{
  128. const { paginatedNotifications } = state.notifications;
  129. return Math.max(...Object.keys(paginatedNotifications));
  130. };
  131. const selectLoadedNotificationsPages = (state)=>{
  132. const { paginatedNotifications } = state.notifications;
  133. return Object.keys(paginatedNotifications);
  134. };
  135. const selectNotificationsIsLoading = (state)=>state.notifications.isLoadingNotifications;
  136. const selectNotificationsIsFetching = (state)=>state.notifications.isFetchingNotifications;
  137. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (notificationsSlice.reducer);
  138. /***/ })
  139. };
  140. ;
  141. //# sourceMappingURL=39953.js.map