2020-06-12 22:44:25 +02:00
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2021-03-24 08:45:41 +01:00
|
|
|
export const selectState = (state) => state.notifications || {};
|
2020-06-12 22:44:25 +02:00
|
|
|
|
2021-03-24 08:45:41 +01:00
|
|
|
export const selectNotifications = createSelector(selectState, (state) => state.notifications);
|
2020-07-23 16:22:57 +02:00
|
|
|
|
2021-03-24 08:45:41 +01:00
|
|
|
export const selectNotificationsFiltered = createSelector(selectState, (state) => state.notificationsFiltered);
|
|
|
|
|
2021-04-29 21:10:20 +02:00
|
|
|
export const selectNotificationCategories = createSelector(selectState, (state) => state.notificationCategories);
|
|
|
|
|
2021-03-24 08:45:41 +01:00
|
|
|
export const makeSelectNotificationForCommentId = (id) =>
|
|
|
|
createSelector(selectNotifications, (notifications) => {
|
2020-10-20 15:29:49 +02:00
|
|
|
const match =
|
|
|
|
notifications &&
|
|
|
|
notifications.find(
|
2021-03-24 08:45:41 +01:00
|
|
|
(n) =>
|
2020-10-20 15:29:49 +02:00
|
|
|
n.notification_parameters &&
|
|
|
|
n.notification_parameters.dynamic &&
|
|
|
|
n.notification_parameters.dynamic.hash === id
|
|
|
|
);
|
|
|
|
return match;
|
|
|
|
});
|
|
|
|
|
2021-03-24 08:45:41 +01:00
|
|
|
export const selectIsFetchingNotifications = createSelector(selectState, (state) => state.fetchingNotifications);
|
2020-07-23 16:22:57 +02:00
|
|
|
|
2021-03-24 08:45:41 +01: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
|
|
|
});
|
|
|
|
|
2021-03-24 08:45:41 +01: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
|
|
|
});
|
|
|
|
|
2021-03-24 08:45:41 +01:00
|
|
|
export const selectToast = createSelector(selectState, (state) => {
|
2020-06-12 22:44:25 +02:00
|
|
|
if (state.toasts.length) {
|
|
|
|
const { id, params } = state.toasts[0];
|
|
|
|
return {
|
|
|
|
id,
|
|
|
|
...params,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2021-03-24 08:45:41 +01:00
|
|
|
export const selectError = createSelector(selectState, (state) => {
|
2020-06-12 22:44:25 +02:00
|
|
|
if (state.errors.length) {
|
|
|
|
const { error } = state.errors[0];
|
|
|
|
return {
|
|
|
|
error,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
});
|