b8ec0c9967
Initially, the filtered list was done at the component level, and the list was simply a subset of `notifications`. But due to the limit issue explained in 5694, we now query the filtered list instead. Considerations: - The filtered list could contain items not listed in the 'All' list. We could add a string at the bottom of 'All' that says "not all items retrieved" if this confuses the user. - The unseen count needs to be based on 'All' and not the filtered one, so that data needs to be stashed somehow (can't re-use the array). Use 2 arrays for now instead of trying to accumulate "all" and "filtered" into 1 array.
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import { createSelector } from 'reselect';
|
|
|
|
export const selectState = (state) => state.notifications || {};
|
|
|
|
export const selectNotifications = createSelector(selectState, (state) => state.notifications);
|
|
|
|
export const selectNotificationsFiltered = createSelector(selectState, (state) => state.notificationsFiltered);
|
|
|
|
export const makeSelectNotificationForCommentId = (id) =>
|
|
createSelector(selectNotifications, (notifications) => {
|
|
const match =
|
|
notifications &&
|
|
notifications.find(
|
|
(n) =>
|
|
n.notification_parameters &&
|
|
n.notification_parameters.dynamic &&
|
|
n.notification_parameters.dynamic.hash === id
|
|
);
|
|
return match;
|
|
});
|
|
|
|
export const selectIsFetchingNotifications = createSelector(selectState, (state) => state.fetchingNotifications);
|
|
|
|
export const selectUnreadNotificationCount = createSelector(selectNotifications, (notifications) => {
|
|
return notifications ? notifications.filter((notification) => !notification.is_read).length : 0;
|
|
});
|
|
|
|
export const selectUnseenNotificationCount = createSelector(selectNotifications, (notifications) => {
|
|
return notifications ? notifications.filter((notification) => !notification.is_seen).length : 0;
|
|
});
|
|
|
|
export const selectToast = createSelector(selectState, (state) => {
|
|
if (state.toasts.length) {
|
|
const { id, params } = state.toasts[0];
|
|
return {
|
|
id,
|
|
...params,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
});
|
|
|
|
export const selectError = createSelector(selectState, (state) => {
|
|
if (state.errors.length) {
|
|
const { error } = state.errors[0];
|
|
return {
|
|
error,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
});
|