var React = require('react'); var Button = require('react-bootstrap/lib/Button'); var ButtonGroup = require('react-bootstrap/lib/ButtonGroup'); var MenuStore = require('../stores/MenuStore'); var MenuActions = require('../actions/MenuActions'); var MiddlePanelActions = require('../actions/MiddlePanelActions'); var FeedItem = React.createClass({ propTypes: {feed_id: React.PropTypes.number.isRequired, title: React.PropTypes.string.isRequired, unread: React.PropTypes.number.isRequired, icon_url: React.PropTypes.string, }, render: function() { var unread = undefined; var icon = undefined; if(this.props.icon_url){ icon = (); } else { icon = (); } if(this.props.unread){ unread = ( {this.props.unread} ); } return (
  • {icon} {this.props.title} {unread}
  • ); }, handleClick: function() { MiddlePanelActions.setFeedFilter(this.props.feed_id); }, }); var Category = React.createClass({ propTypes: {category_id: React.PropTypes.number.isRequired, filter: React.PropTypes.string.isRequired, name: React.PropTypes.string.isRequired, feeds: React.PropTypes.array.isRequired, unread: React.PropTypes.number.isRequired, }, render: function() { var filter = this.props.filter; // filtering according to this.props.filter var feeds = this.props.feeds.filter(function(feed) { if (filter == 'unread' && feed.unread <= 0) {return false;} else if (filter == 'error' && feed.error_count <= 3){return false;} return true; }).sort(function(feed_a, feed_b){ return feed_b.unread - feed_a.unread; }).map(function(feed) { return (); }); var unread = undefined; if(this.props.unread){ unread = ( {this.props.unread} ); } return (

    {this.props.name} {unread}

      {feeds}
    ); }, handleClick: function() { MiddlePanelActions.setCategoryFilter(this.props.category_id); }, }); var Menu = React.createClass({ getInitialState: function() { return {filter: 'all', categories: [], all_unread_count: 0}; }, render: function() { var filter = this.state.filter; return ( ); }, componentDidMount: function() { MenuActions.reload(); MenuStore.addChangeListener(this._onChange); }, componentWillUnmount: function() { MenuStore.removeChangeListener(this._onChange); }, _onChange: function() { var datas = MenuStore.getAll(); this.setState({filter: datas.filter, categories: datas.categories, all_unread_count: datas.all_unread_count}); }, }); module.exports = Menu;