lbry-desktop/ui/redux/selectors/notifications.js

56 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

import { createSelector } from 'reselect';
export const selectState = (state) => state.notifications || {};
export const selectNotifications = createSelector(selectState, (state) => state.notifications);
2020-07-23 16:22:57 +02:00
export const selectNotificationsFiltered = createSelector(selectState, (state) => state.notificationsFiltered);
export const selectNotificationCategories = createSelector(selectState, (state) => state.notificationCategories);
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);
2020-07-23 16:22:57 +02:00
export const selectUnreadNotificationCount = createSelector(selectNotifications, (notifications) => {
return notifications ? notifications.filter((notification) => !notification.is_read).length : 0;
2020-07-23 16:22:57 +02:00
});
export const selectUnseenNotificationCount = createSelector(selectNotifications, (notifications) => {
return notifications ? notifications.filter((notification) => !notification.is_seen).length : 0;
2020-08-21 21:44:54 +02:00
});
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;
});