'use strict'; import React from 'react'; import { Link } from 'react-router'; import DropdownButton from 'react-bootstrap/lib/DropdownButton'; import Glyphicon from 'react-bootstrap/lib/Glyphicon'; import MenuItem from 'react-bootstrap/lib/MenuItem'; import Nav from 'react-bootstrap/lib/Nav'; import NotificationActions from '../actions/notification_actions'; import NotificationStore from '../stores/notification_store'; import { mergeOptions } from '../utils/general_utils'; import { getLangText } from '../utils/lang_utils'; let HeaderNotification = React.createClass({ getInitialState() { return mergeOptions( NotificationStore.getState() ); }, componentDidMount() { NotificationStore.listen(this.onChange); NotificationActions.fetchPieceListNotifications(); NotificationActions.fetchEditionListNotifications(); }, componentWillUnmount() { NotificationStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); }, getPieceNotifications(){ if (this.state.pieceListNotifications && this.state.pieceListNotifications.length > 0) { return (
Artworks ({this.state.pieceListNotifications.length})
{this.state.pieceListNotifications.map((pieceNotification, i) => { return ( ); } )}
); } return null; }, getEditionNotifications(){ if (this.state.editionListNotifications && this.state.editionListNotifications.length > 0) { return (
Editions ({this.state.editionListNotifications.length})
{this.state.editionListNotifications.map((editionNotification, i) => { return ( ); } )}
); } return null; }, render() { if ((this.state.pieceListNotifications && this.state.pieceListNotifications.length > 0) || (this.state.editionListNotifications && this.state.editionListNotifications.length > 0)){ let numNotifications = 0; if (this.state.pieceListNotifications && this.state.pieceListNotifications.length > 0) { numNotifications += this.state.pieceListNotifications.length; } if (this.state.editionListNotifications && this.state.editionListNotifications.length > 0) { numNotifications += this.state.editionListNotifications.length; } return ( ); } return null; } }); let NotificationListItem = React.createClass({ propTypes: { notification: React.PropTypes.array, pieceOrEdition: React.PropTypes.object, }, getNotificationText(){ let numNotifications = null; if (this.props.notification.length > 1){ numNotifications =
+ {this.props.notification.length - 1} {getLangText('more...')}
; } return (
{this.props.notification[0].action_str} {numNotifications}
); }, render() { if (this.props.pieceOrEdition) { return (

{this.props.pieceOrEdition.title}

by {this.props.pieceOrEdition.artist_name}
{this.getNotificationText()}
); } return null; } }); export default HeaderNotification;