dae78c488f
From the previous commit, we are now showing toasts in the reverse order (latest to oldest). Next, extend the "hide snack" timer to handle multiple snacks. It will dismiss them one by one, restarting itself until no more toasts. Show a stacked GUI when there are multiple toasts. Users can still manually dismiss the toasts.
55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
import { createSelector } from 'reselect';
|
|
|
|
export const selectState = (state) => state.notifications || {};
|
|
|
|
export const selectNotifications = (state) => selectState(state).notifications;
|
|
export const selectNotificationsFiltered = (state) => selectState(state).notificationsFiltered;
|
|
export const selectNotificationCategories = (state) => selectState(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 = (state) => selectState(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[state.toasts.length - 1];
|
|
return {
|
|
id,
|
|
...params,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
});
|
|
|
|
export const selectToastCount = (state) => selectState(state).toasts.length;
|
|
|
|
export const selectError = createSelector(selectState, (state) => {
|
|
if (state.errors.length) {
|
|
const { error } = state.errors[0];
|
|
return {
|
|
error,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
});
|