Don't clear all notifications when only 1 is clicked.
## Issue: Closes 5515: All videos marked as read when clicking a single notification from notification list ## Change: - Augment `doReadNotifications` to only clear the given IDs. If the argument is `null` or is not a valid array (e.g. when used as a click handlers, the click event object is passed in), all notifications will be cleared. - Augment `NOTIFICATION_READ_COMPLETED` to only clear the given IDs. ## Notes: - Wasn't sure of the API will fail if the ID is invalid, so I start from `unreadNotifications` first, then only filtering it further with the given ID. Otherwise, we could just skip the `unreadNotifications` filtering.
This commit is contained in:
parent
2e49421960
commit
1e4c79cf06
2 changed files with 24 additions and 10 deletions
|
@ -76,21 +76,27 @@ export function doNotificationList() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doReadNotifications() {
|
export function doReadNotifications(notificationsIds: Array<number>) {
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch, getState: GetState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const notifications = selectNotifications(state);
|
const notifications = selectNotifications(state);
|
||||||
const unreadNotifications =
|
const unreadNotifications = notifications && notifications.filter((notification) => !notification.is_read);
|
||||||
notifications &&
|
|
||||||
notifications
|
let ids;
|
||||||
.filter((notification) => !notification.is_read)
|
if (notificationsIds && Array.isArray(notificationsIds) && notificationsIds.length !== 0) {
|
||||||
.map((notification) => notification.id)
|
// Wipe specified notications.
|
||||||
.join(',');
|
ids = unreadNotifications
|
||||||
|
.filter((notification) => notificationsIds.includes(notification.id))
|
||||||
|
.map((notification) => notification.id);
|
||||||
|
} else {
|
||||||
|
// A null or invalid argument will wipe all unread notifications.
|
||||||
|
ids = unreadNotifications.map((notification) => notification.id);
|
||||||
|
}
|
||||||
|
|
||||||
dispatch({ type: ACTIONS.NOTIFICATION_READ_STARTED });
|
dispatch({ type: ACTIONS.NOTIFICATION_READ_STARTED });
|
||||||
return Lbryio.call('notification', 'edit', { notification_ids: unreadNotifications, is_read: true })
|
return Lbryio.call('notification', 'edit', { notification_ids: ids.join(','), is_read: true })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dispatch({ type: ACTIONS.NOTIFICATION_READ_COMPLETED });
|
dispatch({ type: ACTIONS.NOTIFICATION_READ_COMPLETED, data: { notificationIds: ids } });
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
dispatch({ type: ACTIONS.NOTIFICATION_READ_FAILED, data: { error } });
|
dispatch({ type: ACTIONS.NOTIFICATION_READ_FAILED, data: { error } });
|
||||||
|
|
|
@ -55,8 +55,16 @@ export default handleActions(
|
||||||
},
|
},
|
||||||
[ACTIONS.NOTIFICATION_READ_COMPLETED]: (state, action) => {
|
[ACTIONS.NOTIFICATION_READ_COMPLETED]: (state, action) => {
|
||||||
const { notifications } = state;
|
const { notifications } = state;
|
||||||
|
const { notificationIds } = action.data;
|
||||||
const newNotifications =
|
const newNotifications =
|
||||||
notifications && notifications.map((notification) => ({ ...notification, is_read: true }));
|
notifications &&
|
||||||
|
notifications.map((notification) => {
|
||||||
|
if (notificationIds.includes(notification.id)) {
|
||||||
|
return { ...notification, is_read: true };
|
||||||
|
} else {
|
||||||
|
return { ...notification };
|
||||||
|
}
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
notifications: newNotifications,
|
notifications: newNotifications,
|
||||||
|
|
Loading…
Add table
Reference in a new issue