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-10-23 04:41:43 +02:00
|
|
|
export const selectNotifications = (state) => selectState(state).notifications;
|
|
|
|
export const selectNotificationsFiltered = (state) => selectState(state).notificationsFiltered;
|
|
|
|
export const selectNotificationCategories = (state) => selectState(state).notificationCategories;
|
2021-04-29 21:10:20 +02:00
|
|
|
|
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-10-23 04:41:43 +02:00
|
|
|
export const selectIsFetchingNotifications = (state) => selectState(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) {
|
2022-05-06 10:40:34 +02:00
|
|
|
const { id, params } = state.toasts[state.toasts.length - 1];
|
2020-06-12 22:44:25 +02:00
|
|
|
return {
|
|
|
|
id,
|
|
|
|
...params,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2022-05-06 12:08:09 +02:00
|
|
|
export const selectToastCount = (state) => selectState(state).toasts.length;
|
|
|
|
|
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;
|
|
|
|
});
|