event => notification

This commit is contained in:
Sean Yesmunt 2018-11-12 19:20:52 -05:00
parent b295a7db57
commit 99025a35a4
4 changed files with 78 additions and 83 deletions

90
dist/bundle.js vendored
View file

@ -92,12 +92,12 @@ Object.defineProperty(exports, "__esModule", {
exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.selectAllCostInfoByUri = exports.makeSelectCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = undefined; exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.selectAllCostInfoByUri = exports.makeSelectCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = undefined;
exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.selectBlackListedOutpoints = exports.blacklistReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.costInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doBlackListedOutpointsSubscribe = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doFetchCostInfoForUri = exports.doFetchTrendingUris = exports.doFetchFeaturedUris = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbryapi = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined; exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.selectBlackListedOutpoints = exports.blacklistReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.costInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doBlackListedOutpointsSubscribe = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doFetchCostInfoForUri = exports.doFetchTrendingUris = exports.doFetchFeaturedUris = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbryapi = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined;
var _notification = __webpack_require__(1); var _Notification = __webpack_require__(1);
Object.defineProperty(exports, 'Toast', { Object.defineProperty(exports, 'Toast', {
enumerable: true, enumerable: true,
get: function get() { get: function get() {
return _notification.Toast; return _Notification.Toast;
} }
}); });
@ -1290,8 +1290,8 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
/* /*
Events: Notifications:
- List of notifications based on user interactions/app events - List of notifications based on user interactions/app notifications
- Always saved, but can be manually deleted - Always saved, but can be manually deleted
- Can happen in the background, or because of user interaction (ex: publish confirmed) - Can happen in the background, or because of user interaction (ex: publish confirmed)
*/ */
@ -1299,22 +1299,22 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
type: ACTIONS.CREATE_TOAST, type: ACTIONS.CREATE_TOAST,
data: Toast, data: Toast,
};*/ };*/
/*:: export type Event = { /*:: export type Notification = {
id: string, // Unique id id: string, // Unique id
dateCreated: number, dateCreated: number,
isRead: boolean, // Used to display "new" notifications that a user hasn't seen yet isRead: boolean, // Used to display "new" notifications that a user hasn't seen yet
source?: string, // The type/area an event is from. Used for sorting (ex: publishes, transactions) source?: string, // The type/area an notification is from. Used for sorting (ex: publishes, transactions)
// We may want to use priority/isDismissed in the future to specify how urgent a notification is // We may want to use priority/isDismissed in the future to specify how urgent a notification is
// and if the user should see it immediately // and if the user should see it immediately
// isDissmied: boolean, // isDissmied: boolean,
// priority?: number // priority?: number
};*/ };*/
/*:: export type DoEvent = { /*:: export type DoNotification = {
type: ACTIONS.CREATE_EVENT, type: ACTIONS.CREATE_NOTIFICATION,
data: Event, data: Notification,
};*/ };*/
/*:: export type DoEditEvent = { /*:: export type DoEditNotification = {
type: ACTIONS.EDIT_EVENT, type: ACTIONS.EDIT_NOTIFICATION,
data: { data: {
id: string, id: string,
isRead: boolean, isRead: boolean,
@ -1331,8 +1331,8 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
- Errors that should interupt user behavior - Errors that should interupt user behavior
- For errors that can be shown without interrupting a user, use Toast with the isError flag - For errors that can be shown without interrupting a user, use Toast with the isError flag
*/ */
/*:: export type DoDeleteEvent = { /*:: export type DoDeleteNotification = {
type: ACTIONS.DELETE_EVENT, type: ACTIONS.DELETE_NOTIFICATION,
data: { data: {
id: string, // The id to delete id: string, // The id to delete
}, },
@ -1354,7 +1354,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
type: ACTIONS.DISMISS_ERROR, type: ACTIONS.DISMISS_ERROR,
};*/ };*/
/*:: export type NotificationState = { /*:: export type NotificationState = {
events: Array<Event>, notifications: Array<Notification>,
errors: Array<Error>, errors: Array<Error>,
toasts: Array<Toast>, toasts: Array<Toast>,
};*/ };*/
@ -1581,9 +1581,9 @@ var REMOVE_PENDING_PUBLISH = exports.REMOVE_PENDING_PUBLISH = 'REMOVE_PENDING_PU
var DO_PREPARE_EDIT = exports.DO_PREPARE_EDIT = 'DO_PREPARE_EDIT'; var DO_PREPARE_EDIT = exports.DO_PREPARE_EDIT = 'DO_PREPARE_EDIT';
// Notifications // Notifications
var CREATE_EVENT = exports.CREATE_EVENT = 'CREATE_EVENT'; var CREATE_NOTIFICATION = exports.CREATE_NOTIFICATION = 'CREATE_NOTIFICATION';
var EDIT_EVENT = exports.EDIT_EVENT = 'EDIT_EVENT'; var EDIT_NOTIFICATION = exports.EDIT_NOTIFICATION = 'EDIT_NOTIFICATION';
var DELETE_EVENT = exports.DELETE_EVENT = 'DELETE_EVENT'; var DELETE_NOTIFICATION = exports.DELETE_NOTIFICATION = 'DELETE_NOTIFICATION';
var CREATE_TOAST = exports.CREATE_TOAST = 'CREATE_TOAST'; var CREATE_TOAST = exports.CREATE_TOAST = 'CREATE_TOAST';
var DISMISS_TOAST = exports.DISMISS_TOAST = 'DISMISS_TOAST'; var DISMISS_TOAST = exports.DISMISS_TOAST = 'DISMISS_TOAST';
var CREATE_ERROR = exports.CREATE_ERROR = 'CREATE_ERROR'; var CREATE_ERROR = exports.CREATE_ERROR = 'CREATE_ERROR';
@ -1862,8 +1862,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/*:: import type { ToastParams } from 'types/notification';*/ // @flow // @flow
/*:: import type { ToastParams } from 'types/Notification';*/
function doToast(params /*: ToastParams*/) { function doToast(params /*: ToastParams*/) {
if (!params) { if (!params) {
throw Error("'params' object is required to create a toast notification"); throw Error("'params' object is required to create a toast notification");
@ -2153,10 +2153,8 @@ function doAbandonClaim(txid, nout) {
claimId: claimId claimId: claimId
} }
}); });
dispatch(doNotify({ dispatch((0, _notifications.doToast)({
title: 'Transaction successful', message: 'Successfully abandoned your claim'
message: 'Successfully abandoned your claim',
displayType: ['snackbar', 'toast']
})); }));
// After abandoning, call claim_list_mine to show the claim as abandoned // After abandoning, call claim_list_mine to show the claim as abandoned
@ -6085,14 +6083,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
/*:: import type { /*:: import type {
NotificationState, NotificationState,
DoToast, DoToast,
DoEvent, DoNotification,
DoEditEvent, DoEditNotification,
DoDeleteEvent, DoDeleteNotification,
} from 'types/notification';*/ } from 'types/Notification';*/
var defaultState /*: NotificationState*/ = { var defaultState /*: NotificationState*/ = {
events: [], notifications: [],
toasts: [], toasts: [],
errors: [] errors: []
}; };
@ -6112,42 +6110,36 @@ var notificationsReducer = (0, _reduxUtils.handleActions)((_handleActions = {},
return _extends({}, state, { return _extends({}, state, {
toasts: newToasts toasts: newToasts
}); });
}), _defineProperty(_handleActions, ACTIONS.CREATE_EVENT, function (state /*: NotificationState*/, action /*: DoEvent*/) { }), _defineProperty(_handleActions, ACTIONS.CREATE_NOTIFICATION, function (state /*: NotificationState*/, action /*: DoNotification*/) {
var event = action.data; var notification = action.data;
var newEvents = state.events.slice(); var newNotifications = state.notifications.slice();
newEvents.push(event); newNotifications.push(notification);
return _extends({}, state, { return _extends({}, state, {
events: newEvents notifications: newNotifications
}); });
}), _defineProperty(_handleActions, ACTIONS.EDIT_EVENT, function (state /*: NotificationState*/, action /*: DoEditEvent*/) { }), _defineProperty(_handleActions, ACTIONS.EDIT_NOTIFICATION, function (state /*: NotificationState*/, action /*: DoEditNotification*/) {
var event = action.data.event; var notification = action.data.notification;
var newEvents = state.events.slice(); var notifications = state.notifications.slice();
newEvents = newEvents.map(function (pastEvent) { notifications = notifications.map(function (pastNotification) {
if (pastEvent.id === event.id) { return pastNotification.id === notification.id ? notification : pastNotification;
return _extends({}, pastEvent, {
events: newEvents
});
}
return pastEvent;
}); });
return _extends({}, state, { return _extends({}, state, {
events: newEvents notifications: notifications
}); });
}), _defineProperty(_handleActions, ACTIONS.DELETE_EVENT, function (state /*: NotificationState*/, action /*: DoDeleteEvent*/) { }), _defineProperty(_handleActions, ACTIONS.DELETE_NOTIFICATION, function (state /*: NotificationState*/, action /*: DoDeleteNotification*/) {
var id = action.data.id; var id = action.data.id;
var newEvents = state.events.slice(); var newNotifications = state.notifications.slice();
newEvents = newEvents.filter(function (notification) { newNotifications = newNotifications.filter(function (notification) {
return notification.id !== id; return notification.id !== id;
}); });
return _extends({}, state, { return _extends({}, state, {
events: newEvents notifications: newNotifications
}); });
}), _defineProperty(_handleActions, ACTIONS.CREATE_ERROR, function (state /*: NotificationState*/, action /*: DoToast*/) { }), _defineProperty(_handleActions, ACTIONS.CREATE_ERROR, function (state /*: NotificationState*/, action /*: DoToast*/) {
var error = action.data; var error = action.data;

View file

@ -210,9 +210,9 @@ export const REMOVE_PENDING_PUBLISH = 'REMOVE_PENDING_PUBLISH';
export const DO_PREPARE_EDIT = 'DO_PREPARE_EDIT'; export const DO_PREPARE_EDIT = 'DO_PREPARE_EDIT';
// Notifications // Notifications
export const CREATE_EVENT = 'CREATE_EVENT'; export const CREATE_NOTIFICATION = 'CREATE_NOTIFICATION';
export const EDIT_EVENT = 'EDIT_EVENT'; export const EDIT_NOTIFICATION = 'EDIT_NOTIFICATION';
export const DELETE_EVENT = 'DELETE_EVENT'; export const DELETE_NOTIFICATION = 'DELETE_NOTIFICATION';
export const CREATE_TOAST = 'CREATE_TOAST'; export const CREATE_TOAST = 'CREATE_TOAST';
export const DISMISS_TOAST = 'DISMISS_TOAST'; export const DISMISS_TOAST = 'DISMISS_TOAST';
export const CREATE_ERROR = 'CREATE_ERROR'; export const CREATE_ERROR = 'CREATE_ERROR';

View file

@ -2,15 +2,15 @@
import type { import type {
NotificationState, NotificationState,
DoToast, DoToast,
DoEvent, DoNotification,
DoEditEvent, DoEditNotification,
DoDeleteEvent, DoDeleteNotification,
} from 'types/Notification'; } from 'types/Notification';
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import { handleActions } from 'util/redux-utils'; import { handleActions } from 'util/redux-utils';
const defaultState: NotificationState = { const defaultState: NotificationState = {
events: [], notifications: [],
toasts: [], toasts: [],
errors: [], errors: [],
}; };
@ -38,37 +38,40 @@ const notificationsReducer = handleActions(
}; };
}, },
// Events // Notifications
[ACTIONS.CREATE_EVENT]: (state: NotificationState, action: DoEvent) => { [ACTIONS.CREATE_NOTIFICATION]: (state: NotificationState, action: DoNotification) => {
const event = action.data; const notification = action.data;
const newEvents = state.events.slice(); const newNotifications = state.notifications.slice();
newEvents.push(event); newNotifications.push(notification);
return { return {
...state, ...state,
events: newEvents, notifications: newNotifications,
}; };
}, },
// Used to mark notifications as read/dismissed // Used to mark notifications as read/dismissed
[ACTIONS.EDIT_EVENT]: (state: NotificationState, action: DoEditEvent) => { [ACTIONS.EDIT_NOTIFICATION]: (state: NotificationState, action: DoEditNotification) => {
const { event } = action.data; const { notification } = action.data;
let events = state.events.slice(); let notifications = state.notifications.slice();
events = events.map((pastEvent) => (pastEvent.id === event.id ? event : pastEvent)); notifications = notifications.map(
(pastNotification) =>
pastNotification.id === notification.id ? notification : pastNotification
);
return { return {
...state, ...state,
events, notifications,
}; };
}, },
[ACTIONS.DELETE_EVENT]: (state: NotificationState, action: DoDeleteEvent) => { [ACTIONS.DELETE_NOTIFICATION]: (state: NotificationState, action: DoDeleteNotification) => {
const { id } = action.data; const { id } = action.data;
let newEvents = state.events.slice(); let newNotifications = state.notifications.slice();
newEvents = newEvents.filter((notification) => notification.id !== id); newNotifications = newNotifications.filter((notification) => notification.id !== id);
return { return {
...state, ...state,
events: newEvents, notifications: newNotifications,
}; };
}, },

View file

@ -28,29 +28,29 @@ export type DoToast = {
}; };
/* /*
Events: Notifications:
- List of notifications based on user interactions/app events - List of notifications based on user interactions/app notifications
- Always saved, but can be manually deleted - Always saved, but can be manually deleted
- Can happen in the background, or because of user interaction (ex: publish confirmed) - Can happen in the background, or because of user interaction (ex: publish confirmed)
*/ */
export type Event = { export type Notification = {
id: string, // Unique id id: string, // Unique id
dateCreated: number, dateCreated: number,
isRead: boolean, // Used to display "new" notifications that a user hasn't seen yet isRead: boolean, // Used to display "new" notifications that a user hasn't seen yet
source?: string, // The type/area an event is from. Used for sorting (ex: publishes, transactions) source?: string, // The type/area an notification is from. Used for sorting (ex: publishes, transactions)
// We may want to use priority/isDismissed in the future to specify how urgent a notification is // We may want to use priority/isDismissed in the future to specify how urgent a notification is
// and if the user should see it immediately // and if the user should see it immediately
// isDissmied: boolean, // isDissmied: boolean,
// priority?: number // priority?: number
}; };
export type DoEvent = { export type DoNotification = {
type: ACTIONS.CREATE_EVENT, type: ACTIONS.CREATE_NOTIFICATION,
data: Event, data: Notification,
}; };
export type DoEditEvent = { export type DoEditNotification = {
type: ACTIONS.EDIT_EVENT, type: ACTIONS.EDIT_NOTIFICATION,
data: { data: {
id: string, id: string,
isRead: boolean, isRead: boolean,
@ -60,8 +60,8 @@ export type DoEditEvent = {
}, },
}; };
export type DoDeleteEvent = { export type DoDeleteNotification = {
type: ACTIONS.DELETE_EVENT, type: ACTIONS.DELETE_NOTIFICATION,
data: { data: {
id: string, // The id to delete id: string, // The id to delete
}, },
@ -91,7 +91,7 @@ export type DoDismissError = {
NotificationState NotificationState
*/ */
export type NotificationState = { export type NotificationState = {
events: Array<Event>, notifications: Array<Notification>,
errors: Array<Error>, errors: Array<Error>,
toasts: Array<Toast>, toasts: Array<Toast>,
}; };