From ed74f6a2bfc9975092040c4379f459d4c9442d3f Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Fri, 22 Jan 2016 19:09:08 +0100 Subject: renaming, proper usage of props and state, filtering left menu --- src/web/js/components/Menu.react.js | 70 ++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 40 deletions(-) (limited to 'src/web/js/components/Menu.react.js') diff --git a/src/web/js/components/Menu.react.js b/src/web/js/components/Menu.react.js index c1cee9de..ef0ec274 100644 --- a/src/web/js/components/Menu.react.js +++ b/src/web/js/components/Menu.react.js @@ -12,77 +12,65 @@ var FeedItem = React.createClass({ unread: React.PropTypes.number.isRequired, icon_url: React.PropTypes.string, }, - getInitialState: function() { - return {feed_id: this.props.feed_id, - title: this.props.title, - unread: this.props.unread, - icon_url: this.props.icon_url, - }; - }, render: function() { var unread = undefined; var icon = undefined; - if(this.state.icon_url){ - icon = (); + if(this.props.icon_url){ + icon = (); } else { icon = (); } - if(this.state.unread){ + if(this.props.unread){ unread = ( - {this.state.unread} + {this.props.unread} ); } return (
  • - {icon} {this.state.title} {unread} + {icon} {this.props.title} {unread}
  • ); }, handleClick: function() { - MiddlePanelActions.setFeedFilter(this.state.feed_id); + 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, }, - getInitialState: function() { - return {category_id: this.props.category_id, - name: this.props.name, - feeds: this.props.feeds, - unread: this.props.unread, - }; - }, render: function() { - unread = undefined; - if(this.state.unread){ - unread = ( - - {this.state.unread} - - ); + var filter = 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; + }).map(function(feed) { + return (); + }); + var unread = undefined; + if(this.props.unread){ + unread = ( + {this.props.unread} + ); } return (

    - {this.state.name} {unread} + {this.props.name} {unread}

    -
      - {this.state.feeds.map(function(feed){ - return ;})} -
    +
      {feeds}
    ); }, handleClick: function() { - MiddlePanelActions.setCategoryFilter(this.state.category_id); + MiddlePanelActions.setCategoryFilter(this.props.category_id); }, }); @@ -91,21 +79,23 @@ var Menu = React.createClass({ return {filter: 'all', categories: [], all_unread_count: 0}; }, render: function() { + var filter = this.state.filter; return (