Discard distinction between dismiss and delete in favor of dismiss
Also removing the created timestamp as that isn’t being used for anythingpull/2910/head
parent
bb6e2120d2
commit
d6c1cd610c
|
@ -3,7 +3,6 @@ import reducer, {initialState} from 'src/shared/reducers/notifications'
|
|||
import {
|
||||
publishNotification,
|
||||
dismissNotification,
|
||||
deleteNotification,
|
||||
} from 'src/shared/actions/notifications'
|
||||
|
||||
const notificationID = '000'
|
||||
|
@ -12,13 +11,11 @@ const exampleNotification = {
|
|||
id: notificationID,
|
||||
type: 'success',
|
||||
message: 'Hell yeah you are a real notification!',
|
||||
created: 'timestamp',
|
||||
duration: 5000, // -1 stays until dismissed
|
||||
icon: 'zap',
|
||||
dismiss: false,
|
||||
}
|
||||
|
||||
const exampleNotifications = [exampleNotification]
|
||||
const exampleNotifications = [exampleNotification] // -> []
|
||||
|
||||
describe('Shared.Reducers.notifications', () => {
|
||||
it('should publish a notification', () => {
|
||||
|
@ -36,20 +33,7 @@ describe('Shared.Reducers.notifications', () => {
|
|||
exampleNotifications,
|
||||
dismissNotification(notificationID)
|
||||
)
|
||||
const expected = exampleNotifications.map(n => {
|
||||
return n.id === notificationID ? {...n, dismiss: true} : n
|
||||
})
|
||||
|
||||
expect(actual).to.equal(expected)
|
||||
})
|
||||
|
||||
it('should delete a notification', () => {
|
||||
const actual = reducer(
|
||||
exampleNotifications,
|
||||
deleteNotification(notificationID)
|
||||
)
|
||||
const expected = exampleNotifications.filter(n => n.id !== notificationID)
|
||||
|
||||
expect(actual).to.equal(expected)
|
||||
expect(actual.length).to.be(0)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -18,21 +18,10 @@ export function publishNotification(notification) {
|
|||
}
|
||||
}
|
||||
|
||||
export function dismissNotification(notificationID) {
|
||||
export function dismissNotification(id) {
|
||||
return {
|
||||
type: 'DISMISS_NOTIFICATION',
|
||||
payload: {
|
||||
notificationID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteNotification(notificationID) {
|
||||
return {
|
||||
type: 'DELETE_NOTIFICATION',
|
||||
payload: {
|
||||
notificationID,
|
||||
},
|
||||
payload: {id},
|
||||
}
|
||||
}
|
||||
>>>>>>> WIP Refactor Notifications
|
||||
|
|
|
@ -7,8 +7,6 @@ export const notifications = (state = initialState, action) => {
|
|||
const notification = {
|
||||
...action.payload.notification,
|
||||
id: uuid.v4(),
|
||||
created: Date.now(),
|
||||
dismiss: false,
|
||||
}
|
||||
const newNotification = [notification]
|
||||
// Hacky way to add the new notifcation to the front of the list
|
||||
|
@ -16,15 +14,8 @@ export const notifications = (state = initialState, action) => {
|
|||
}
|
||||
|
||||
case 'DISMISS_NOTIFICATION': {
|
||||
const {notificationID} = action.payload
|
||||
|
||||
return state.map(n => {
|
||||
return n.id === notificationID ? {...n, dismiss: true} : n
|
||||
})
|
||||
}
|
||||
|
||||
case 'DELETE_NOTIFICATION': {
|
||||
return state.filter(n => n.id === action.payload)
|
||||
const {id} = action.payload
|
||||
return state.filter(n => n.id !== id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue