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AAsB,CAAC,CAAyB;IAC1F,OAAO,CAAC,CAACA,sBAAsB,CAACwC,QAAQ,CAAC,EAAEG,OAAO,CAAC;AACrD,CAAC,CAAC;AACK,MAAMC,iCAAiC,GAAG,CAAClD,KAAgB,GAAK;IACrE,MAAM,EAAEM,sBAAsB,GAAE,GAAGN,KAAK,CAACa,aAAa;IACtD,OAAOkC,IAAI,CAACC,GAAG,IAAK5C,MAAM,CAACC,IAAI,CAACC,sBAAsB,CAAC,CAAyB,CAAC;AACnF,CAAC,CAAC;AACK,MAAM6C,8BAA8B,GAAG,CAACnD,KAAgB,GAAK;IAClE,MAAM,EAAEM,sBAAsB,GAAE,GAAGN,KAAK,CAACa,aAAa;IACtD,OAAOT,MAAM,CAACC,IAAI,CAACC,sBAAsB,CAAC,CAAwB;AACpE,CAAC,CAAC;AACK,MAAM8C,4BAA4B,GAAG,CAACpD,KAAgB,GAC3DA,KAAK,CAACa,aAAa,CAACQ,sBAAsB,CAAC;AACtC,MAAMgC,6BAA6B,GAAG,CAACrD,KAAgB,GAC5DA,KAAK,CAACa,aAAa,CAACW,uBAAuB,CAAC;AAE9C,iEAAeV,kBAAkB,CAACwC,OAAO,EAAC","sources":["webpack://quran.com/./src/redux/slices/notifications.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { IMessage } from '@novu/shared';\nimport { createSlice, PayloadAction } from '@reduxjs/toolkit';\n\nimport { getNotificationsInitialState } from '../defaultSettings/util';\nimport NotificationsState from '../types/NotificationsState';\n\nimport { RootState } from '@/redux/RootState';\nimport SliceName from '@/redux/types/SliceName';\n\n// A helper function to clone and process the notifications while keeping the pagination intact.\nconst cloneAndProcessNotifications = (\n state: NotificationsState,\n processor: (data: IMessage[]) => IMessage[],\n) => {\n const newPagedNotifications: NotificationsState['paginatedNotifications'] = {};\n const newNotifications: NotificationsState['notifications'] = [];\n\n Object.keys(state.paginatedNotifications).forEach((pageKey) => {\n const old = {\n ...state.paginatedNotifications[pageKey],\n data: [...state.paginatedNotifications[pageKey].data],\n };\n const newData = processor(old.data);\n newPagedNotifications[pageKey] = {\n ...old,\n data: newData,\n };\n newNotifications.push(...newData);\n });\n\n return {\n notifications: newNotifications,\n paginatedNotifications: newPagedNotifications,\n };\n};\n\nexport const notificationsSlice = createSlice({\n name: SliceName.NOTIFICATIONS,\n initialState: getNotificationsInitialState(),\n reducers: {\n setNotificationsLoading: (\n state: NotificationsState,\n action: PayloadAction<{\n isLoading: boolean;\n isFetching: boolean;\n shouldResetOldData?: boolean;\n }>,\n ) => ({\n ...state,\n isLoadingNotifications: action.payload.isLoading,\n isFetchingNotifications: action.payload.isFetching,\n\n /**\n * reset the notifications if the flag is set to true\n * this is useful when we want to fetch the data from the beginning when the user re-opens the notification widget\n */\n ...(action.payload.shouldResetOldData\n ? { notifications: [], paginatedNotifications: {} }\n : {}),\n }),\n setNotificationsPageAndFinishLoading: (\n state: NotificationsState,\n action: PayloadAction<{\n page: number;\n data: NotificationsState['paginatedNotifications'][number];\n shouldResetOldData?: boolean;\n }>,\n ) => {\n const newPagedNotifications = {\n ...(action.payload.shouldResetOldData ? {} : state.paginatedNotifications),\n [action.payload.page]: action.payload.data,\n };\n // eslint-disable-next-line unicorn/no-array-reduce\n const newNotifications = Object.keys(newPagedNotifications).reduce((acc, pageKey) => {\n return [...acc, ...newPagedNotifications[pageKey].data];\n }, []);\n\n return {\n ...state,\n paginatedNotifications: newPagedNotifications,\n notifications: newNotifications,\n isLoadingNotifications: false,\n isFetchingNotifications: false,\n };\n },\n setUnseenCount: (state: NotificationsState, action: PayloadAction<number>) => ({\n ...state,\n unseenCount: action.payload,\n }),\n setAllAsRead: (state: NotificationsState) => {\n return {\n ...state,\n ...cloneAndProcessNotifications(state, (notifications) =>\n notifications.map((notification) => ({\n ...notification,\n read: true,\n })),\n ),\n };\n },\n setNotificationAsRead: (\n state: NotificationsState,\n action: PayloadAction<{ messageId: string }>,\n ) => {\n return {\n ...state,\n ...cloneAndProcessNotifications(state, (notifications) =>\n notifications.map((notification) => {\n // eslint-disable-next-line no-underscore-dangle\n if (notification._id === action.payload.messageId) {\n return {\n ...notification,\n read: true,\n };\n }\n return notification;\n }),\n ),\n };\n },\n setDeleteNotification: (\n state: NotificationsState,\n action: PayloadAction<{ messageId: string }>,\n ) => {\n return {\n ...state,\n ...cloneAndProcessNotifications(state, (notifications) =>\n notifications.filter((notification) => {\n // eslint-disable-next-line no-underscore-dangle\n return notification._id !== action.payload.messageId;\n }),\n ),\n };\n },\n },\n});\n\nexport const {\n setNotificationsLoading,\n setNotificationsPageAndFinishLoading,\n setUnseenCount,\n setAllAsRead,\n setNotificationAsRead,\n setDeleteNotification,\n} = notificationsSlice.actions;\n\nexport const selectUnseenCount = (state: RootState) => state.notifications.unseenCount;\nexport const selectNotifications = (state: RootState) => state.notifications.notifications;\nexport const selectHasMoreNotifications = (state: RootState) => {\n const { paginatedNotifications } = state.notifications;\n const lastPage = Math.max(...(Object.keys(paginatedNotifications) as unknown as number[]));\n return !!paginatedNotifications[lastPage]?.hasMore;\n};\nexport const selectLastLoadedNotificationsPage = (state: RootState) => {\n const { paginatedNotifications } = state.notifications;\n return Math.max(...(Object.keys(paginatedNotifications) as unknown as number[]));\n};\nexport const selectLoadedNotificationsPages = (state: RootState) => {\n const { paginatedNotifications } = state.notifications;\n return Object.keys(paginatedNotifications) as unknown as number[];\n};\nexport const selectNotificationsIsLoading = (state: RootState) =>\n state.notifications.isLoadingNotifications;\nexport const selectNotificationsIsFetching = (state: RootState) =>\n state.notifications.isFetchingNotifications;\n\nexport default notificationsSlice.reducer;\n"],"names":["createSlice","getNotificationsInitialState","SliceName","cloneAndProcessNotifications","state","processor","newPagedNotifications","newNotifications","Object","keys","paginatedNotifications","forEach","pageKey","old","data","newData","push","notifications","notificationsSlice","name","NOTIFICATIONS","initialState","reducers","setNotificationsLoading","action","isLoadingNotifications","payload","isLoading","isFetchingNotifications","isFetching","shouldResetOldData","setNotificationsPageAndFinishLoading","page","reduce","acc","setUnseenCount","unseenCount","setAllAsRead","map","notification","read","setNotificationAsRead","_id","messageId","setDeleteNotification","filter","actions","selectUnseenCount","selectNotifications","selectHasMoreNotifications","lastPage","Math","max","hasMore","selectLastLoadedNotificationsPage","selectLoadedNotificationsPages","selectNotificationsIsLoading","selectNotificationsIsFetching","reducer"],"sourceRoot":""}
|