metamaps--metamaps/frontend/src/components/App/NotificationBox.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import onClickOutsideAddon from 'react-onclickoutside'
2017-09-22 22:38:38 +00:00
import Notification from '../Notification'
class NotificationBox extends Component {
static propTypes = {
notifications: PropTypes.array,
fetchNotifications: PropTypes.func.isRequired,
2017-09-22 22:38:38 +00:00
toggleNotificationsBox: PropTypes.func.isRequired,
markAsRead: PropTypes.func.isRequired,
markAsUnread: PropTypes.func.isRequired
}
componentDidMount = () => {
const { notifications, fetchNotifications } = this.props
if (!notifications) {
fetchNotifications()
}
}
handleClickOutside = () => {
this.props.toggleNotificationsBox()
}
render = () => {
2017-09-22 22:38:38 +00:00
const { notifications, markAsRead, markAsUnread } = this.props
return <div className='notificationsBox'>
<div className='notificationsBoxTriangle' />
2017-09-22 22:38:38 +00:00
<ul className='notifications'>
{!notifications && <li>loading...</li>}
2017-09-25 19:21:04 +00:00
{notifications && notifications.slice(0, 10).map(n => {
2017-09-22 22:38:38 +00:00
return <Notification notification={n}
markAsRead={markAsRead}
markAsUnread={markAsUnread}
key={`notification-${n.id}`} />
})}
</ul>
<a href='/notifications' className='notificationsBoxSeeAll'>See all</a>
</div>
}
}
export default onClickOutsideAddon(NotificationBox)