Skip to content

Commit

Permalink
Fix notifications clear issue on infinite scroll (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k committed Jul 8, 2020
1 parent 21288a0 commit c4b46ff
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/actions/notification.js
Expand Up @@ -63,16 +63,37 @@ export const getAllNotifications = ({ pageNo = 1 }) => async (dispatch) => {

export const markNotificationAsRead = ({ primaryActorId, primaryActorType }) => async (
dispatch,
getState,
) => {
const {
data: { payload, meta },
} = getState().notification;
try {
const apiUrl = 'notifications/read_all';
await APIHelper.post(apiUrl, {
primary_actor_type: primaryActorType,
primary_actor_id: primaryActorId,
});
setTimeout(() => {
dispatch(getAllNotifications({ pageNo: 1 }));
}, 500);

const updatedNotifications = payload.map((item, index) => {
if (item.primary_actor_id === primaryActorId) {
item.read_at = 'read_at';
item.mass = 'mass';
}
return item;
});

const { unread_count } = meta;

const updatedUnReadCount = unread_count ? unread_count - 1 : unread_count;

dispatch({
type: UPDATE_ALL_NOTIFICATIONS,
payload: {
notifications: updatedNotifications,
meta: { unread_count: updatedUnReadCount },
},
});
} catch {}
};

Expand All @@ -89,8 +110,6 @@ export const markAllNotificationAsRead = () => async (dispatch, getState) => {
return item;
});

dispatch(getAllNotifications({ pageNo: 1 }));

dispatch({
type: UPDATE_ALL_NOTIFICATIONS,
payload: {
Expand Down

0 comments on commit c4b46ff

Please sign in to comment.