@@ -13,11 +13,11 @@ import type {
13
13
ApiNotificationJSON ,
14
14
} from 'flavours/glitch/api_types/notifications' ;
15
15
import type { ApiStatusJSON } from 'flavours/glitch/api_types/statuses' ;
16
- import type { AppDispatch , RootState } from 'flavours/glitch/store' ;
16
+ import type { AppDispatch } from 'flavours/glitch/store' ;
17
17
import { createDataLoadingThunk } from 'flavours/glitch/store/typed_functions' ;
18
18
19
19
import { importFetchedAccounts , importFetchedStatuses } from './importer' ;
20
- import { decreasePendingNotificationsCount } from './notification_policies' ;
20
+ import { decreasePendingRequestsCount } from './notification_policies' ;
21
21
22
22
// TODO: refactor with notification_groups
23
23
function dispatchAssociatedRecords (
@@ -169,19 +169,11 @@ export const expandNotificationsForRequest = createDataLoadingThunk(
169
169
} ,
170
170
) ;
171
171
172
- const selectNotificationCountForRequest = ( state : RootState , id : string ) => {
173
- const requests = state . notificationRequests . items ;
174
- const thisRequest = requests . find ( ( request ) => request . id === id ) ;
175
- return thisRequest ? thisRequest . notifications_count : 0 ;
176
- } ;
177
-
178
172
export const acceptNotificationRequest = createDataLoadingThunk (
179
173
'notificationRequest/accept' ,
180
174
( { id } : { id : string } ) => apiAcceptNotificationRequest ( id ) ,
181
- ( _data , { dispatch, getState, discardLoadData, actionArg : { id } } ) => {
182
- const count = selectNotificationCountForRequest ( getState ( ) , id ) ;
183
-
184
- dispatch ( decreasePendingNotificationsCount ( count ) ) ;
175
+ ( _data , { dispatch, discardLoadData } ) => {
176
+ dispatch ( decreasePendingRequestsCount ( 1 ) ) ;
185
177
186
178
// The payload is not used in any functions
187
179
return discardLoadData ;
@@ -191,10 +183,8 @@ export const acceptNotificationRequest = createDataLoadingThunk(
191
183
export const dismissNotificationRequest = createDataLoadingThunk (
192
184
'notificationRequest/dismiss' ,
193
185
( { id } : { id : string } ) => apiDismissNotificationRequest ( id ) ,
194
- ( _data , { dispatch, getState, discardLoadData, actionArg : { id } } ) => {
195
- const count = selectNotificationCountForRequest ( getState ( ) , id ) ;
196
-
197
- dispatch ( decreasePendingNotificationsCount ( count ) ) ;
186
+ ( _data , { dispatch, discardLoadData } ) => {
187
+ dispatch ( decreasePendingRequestsCount ( 1 ) ) ;
198
188
199
189
// The payload is not used in any functions
200
190
return discardLoadData ;
@@ -204,13 +194,8 @@ export const dismissNotificationRequest = createDataLoadingThunk(
204
194
export const acceptNotificationRequests = createDataLoadingThunk (
205
195
'notificationRequests/acceptBulk' ,
206
196
( { ids } : { ids : string [ ] } ) => apiAcceptNotificationRequests ( ids ) ,
207
- ( _data , { dispatch, getState, discardLoadData, actionArg : { ids } } ) => {
208
- const count = ids . reduce (
209
- ( count , id ) => count + selectNotificationCountForRequest ( getState ( ) , id ) ,
210
- 0 ,
211
- ) ;
212
-
213
- dispatch ( decreasePendingNotificationsCount ( count ) ) ;
197
+ ( _data , { dispatch, discardLoadData, actionArg : { ids } } ) => {
198
+ dispatch ( decreasePendingRequestsCount ( ids . length ) ) ;
214
199
215
200
// The payload is not used in any functions
216
201
return discardLoadData ;
@@ -220,13 +205,8 @@ export const acceptNotificationRequests = createDataLoadingThunk(
220
205
export const dismissNotificationRequests = createDataLoadingThunk (
221
206
'notificationRequests/dismissBulk' ,
222
207
( { ids } : { ids : string [ ] } ) => apiDismissNotificationRequests ( ids ) ,
223
- ( _data , { dispatch, getState, discardLoadData, actionArg : { ids } } ) => {
224
- const count = ids . reduce (
225
- ( count , id ) => count + selectNotificationCountForRequest ( getState ( ) , id ) ,
226
- 0 ,
227
- ) ;
228
-
229
- dispatch ( decreasePendingNotificationsCount ( count ) ) ;
208
+ ( _data , { dispatch, discardLoadData, actionArg : { ids } } ) => {
209
+ dispatch ( decreasePendingRequestsCount ( ids . length ) ) ;
230
210
231
211
// The payload is not used in any functions
232
212
return discardLoadData ;
0 commit comments