2016-12-13 11:08:13 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import FontAwesome from 'react-fontawesome'
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
export default class Notifications extends React.Component{
|
2016-12-13 11:08:13 +13:00
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
renderNotifications(){
|
|
|
|
|
if (!this.props.notifications || this.props.notifications.length <= 0) return null
|
2016-12-13 11:08:13 +13:00
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
// we only care about the last notification
|
|
|
|
|
var notification = this.props.notifications[this.props.notifications.length-1]
|
2016-12-13 11:08:13 +13:00
|
|
|
|
2017-04-05 09:01:20 +12:00
|
|
|
return (
|
|
|
|
|
<span>
|
|
|
|
|
{
|
|
|
|
|
this.props.notifications.map(notification => {
|
|
|
|
|
switch (notification.type){
|
|
|
|
|
case 'shortcut':
|
|
|
|
|
return (
|
2017-04-05 20:28:41 +12:00
|
|
|
<div className="shortcut-notification" key={notification.key}>
|
2017-04-05 09:01:20 +12:00
|
|
|
<FontAwesome name={notification.content} />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
2017-04-05 20:28:41 +12:00
|
|
|
case 'process':
|
2017-04-05 09:01:20 +12:00
|
|
|
return (
|
2017-04-05 20:28:41 +12:00
|
|
|
<div className="process notification" key={notification.key}>
|
|
|
|
|
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.cancelProcess(notification.key) } />
|
2017-04-05 09:01:20 +12:00
|
|
|
{ notification.content }
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return (
|
2017-04-05 20:28:41 +12:00
|
|
|
<div className={notification.type+" notification"} key={notification.key}>
|
|
|
|
|
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.removeNotification(notification.key) } />
|
2017-04-05 09:01:20 +12:00
|
|
|
{ notification.content }
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</span>
|
|
|
|
|
)
|
2016-12-13 11:08:13 +13:00
|
|
|
}
|
|
|
|
|
|
2017-04-05 09:01:20 +12:00
|
|
|
// do we want the loading of everything to be displayed?
|
|
|
|
|
// not likely...
|
2017-04-03 20:58:47 +12:00
|
|
|
renderLoader(){
|
|
|
|
|
if (!this.props.load_queue){
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var load_queue = this.props.load_queue
|
|
|
|
|
var is_loading = false
|
|
|
|
|
for (var key in load_queue){
|
|
|
|
|
if (load_queue.hasOwnProperty(key)){
|
|
|
|
|
is_loading = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_loading){
|
|
|
|
|
return (
|
|
|
|
|
<div className="notification loading">
|
|
|
|
|
Loading
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2016-12-13 11:08:13 +13:00
|
|
|
}
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
render(){
|
|
|
|
|
return (
|
|
|
|
|
<div className="notifications">
|
|
|
|
|
{this.renderNotifications()}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|