Skip to content

Commit 688c92c

Browse files
author
Yang Zhen
committed
Recover notification
1 parent f5edb80 commit 688c92c

File tree

2 files changed

+11
-61
lines changed

2 files changed

+11
-61
lines changed

app/components/Notification/actions.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import state from './state'
44
export const NOTIFY_TYPE = {
55
ERROR: 'error',
66
INFO: 'info',
7-
SUCCESS: 'success',
8-
WARNING: 'warning'
97
}
108

119
export const NOTIFICATION_REMOVE = 'NOTIFICATION_REMOVE'
@@ -15,14 +13,12 @@ export const removeNotification = registerAction.normal(NOTIFICATION_REMOVE, (no
1513
})
1614

1715
const NOTIFICATION_ADD = 'NOTIFICATION_ADD'
18-
export const addNotification = registerAction.normal(
19-
NOTIFICATION_ADD,
16+
export const addNotification = registerAction.normal(NOTIFICATION_ADD,
2017
(notification) => {
2118
const notifKey = Date.now()
2219
let defaultNotification = {
2320
message: '',
24-
action: '',
25-
notifyType: NOTIFY_TYPE.SUCCESS, // 默认弹出success弹窗
21+
action: 'Dismiss',
2622
key: notifKey,
2723
dismissAfter: 6000,
2824
onClick: () => removeNotification(notifKey)
@@ -32,7 +28,7 @@ export const addNotification = registerAction.normal(
3228
defaultNotification = {
3329
...defaultNotification,
3430
barStyle: { backgroundColor: 'red' },
35-
actionStyle: { color: 'white' }
31+
actionStyle: { color: 'white' },
3632
}
3733
}
3834

app/components/Notification/index.jsx

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,40 @@ import { NotificationStack } from 'react-notification'
44
import * as actions from './actions'
55
import state from './state'
66

7-
const actionStyleFactory = (index, style) =>
8-
Object.assign({}, style, {
9-
color: '#ccc',
10-
right: '-100%',
11-
bottom: 'initial',
12-
top: `${2 + index * 4}rem`,
13-
zIndex: 20,
14-
fontSize: '12px',
15-
padding: '8px'
16-
})
17-
const barStyleFactory = (index, style) =>
18-
Object.assign({}, style, {
7+
const barStyleFactory = (index, style) => {
8+
return Object.assign({}, style, {
199
left: 'initial',
2010
right: '-100%',
2111
bottom: 'initial',
2212
top: `${2 + index * 4}rem`,
2313
zIndex: 20,
2414
fontSize: '12px',
25-
padding: '8px'
15+
padding: '8px',
2616
})
17+
}
2718

28-
const activeBarStyleFactory = (index, style) =>
29-
Object.assign({}, style, {
19+
const activeBarStyleFactory = (index, style) => {
20+
return Object.assign({}, style, {
3021
left: 'initial',
3122
right: '1rem',
3223
bottom: 'initial',
3324
top: `${2 + index * 4}rem`,
3425
fontSize: '12px',
35-
padding: '8px'
26+
padding: '8px',
3627
})
37-
38-
function notificationMessageFactory (notifyType, message) {
39-
let ClassName
40-
let Color
41-
switch (notifyType) {
42-
case 'error':
43-
ClassName = 'fa fa-times-circle'
44-
Color = 'red'
45-
break
46-
case 'success':
47-
ClassName = 'fa fa-check-circle'
48-
Color = 'green'
49-
break
50-
case 'warning':
51-
ClassName = 'fa fa-exclamation-triangle'
52-
Color = 'orange'
53-
break
54-
case 'info':
55-
ClassName = 'fa fa-info-circle'
56-
Color = 'blue'
57-
break
58-
default:
59-
}
60-
return (
61-
<span style={{ fontSize: 12 }}>
62-
<span style={{ color: Color }}>
63-
<i className={ClassName} aria-hidden='true' />
64-
</span>
65-
&nbsp;&nbsp;{message}
66-
</span>
67-
)
6828
}
6929

7030
class Notification extends Component {
7131
constructor (props) {
7232
super()
7333
}
74-
7534
render () {
76-
const notifications = this.props.notifications.map((v) => {
77-
v.action = <i className='fa fa-close' aria-hidden='true' />
78-
v.message = notificationMessageFactory(v.notifyType, v.message)
79-
return v
80-
})
35+
const { notifications } = this.props
8136
return (
8237
<NotificationStack
8338
notifications={notifications}
8439
onDismiss={notification => actions.removeNotification(notification.key)}
8540
barStyleFactory={barStyleFactory}
86-
actionStyleFactory={actionStyleFactory}
8741
activeBarStyleFactory={activeBarStyleFactory}
8842
/>
8943
)

0 commit comments

Comments
 (0)