Skip to content

Commit b7b909f

Browse files
committed
console: Update items after status chnage
1 parent 3af82d5 commit b7b909f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

pkg/webui/console/containers/notifications/notification-list/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,25 @@ const NotificationList = ({
6767
const handleClick = useCallback(
6868
async (_, id) => {
6969
const clickedNotification = items.find(notification => notification.id === id)
70+
const index = items.findIndex(notification => notification.id === id)
7071
if (!isArchive && !('status' in clickedNotification) && totalUnseenCount > 0) {
7172
await dispatch(attachPromise(updateNotificationStatus([id], 'NOTIFICATION_STATUS_SEEN')))
73+
loadNextPage(index, index + 1)
7274
}
7375
},
74-
[items, dispatch, isArchive, totalUnseenCount],
76+
[items, dispatch, isArchive, totalUnseenCount, loadNextPage],
7577
)
7678

7779
const handleMarkAllAsSeen = useCallback(async () => {
7880
if (totalUnseenCount > 0) {
79-
await dispatch(attachPromise(markAllAsSeen()))
81+
const result = await dispatch(attachPromise(markAllAsSeen()))
82+
const firstIndex = items.findIndex(notification => notification.id === result[0])
83+
const lastIndex = items.findIndex(
84+
notification => notification.id === result[result.length - 1],
85+
)
86+
loadNextPage(firstIndex, lastIndex)
8087
}
81-
}, [dispatch, totalUnseenCount])
88+
}, [dispatch, totalUnseenCount, loadNextPage, items])
8289

8390
const classes = classNames(styles.notificationHeaderIcon)
8491

pkg/webui/console/store/middleware/logics/notifications.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const m = defineMessage({
3232
const updateThroughPagination = async (totalCount, userId) => {
3333
let page = 1
3434
const limit = 100
35-
let result
35+
let result = []
3636

3737
while ((page - 1) * limit < totalCount) {
3838
// Get the next page of notifications.
@@ -47,13 +47,13 @@ const updateThroughPagination = async (totalCount, userId) => {
4747
const notificationIds = notifications.notifications.map(notification => notification.id)
4848
// Make the update request.
4949
// eslint-disable-next-line no-await-in-loop
50-
const updatedNotifications = await tts.Notifications.updateNotificationStatus(
50+
await tts.Notifications.updateNotificationStatus(
5151
userId,
5252
notificationIds,
5353
'NOTIFICATION_STATUS_SEEN',
5454
)
5555

56-
result = { ...result, ...updatedNotifications }
56+
result = [...result, ...notificationIds]
5757
page += 1
5858
}
5959

@@ -133,9 +133,8 @@ const markAllAsSeenLogic = createRequestLogic({
133133
process: async ({ getState }) => {
134134
const id = selectUserId(getState())
135135
const totalUnseenCount = selectTotalUnseenCount(getState())
136-
const result = updateThroughPagination(totalUnseenCount, id)
137136

138-
return { ...result, ids: [] }
137+
return updateThroughPagination(totalUnseenCount, id)
139138
},
140139
})
141140

0 commit comments

Comments
 (0)