diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2016-01-28 22:47:36 +0100 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-01-28 22:47:36 +0100 |
commit | 8e942f6f5695c4788328b4959527b30ff31e771d (patch) | |
tree | 1d6caa3d4b1d102ed804215d21bad8a04f9a00ff | |
parent | slight redo of middle panel (diff) | |
download | newspipe-8e942f6f5695c4788328b4959527b30ff31e771d.tar.gz newspipe-8e942f6f5695c4788328b4959527b30ff31e771d.tar.bz2 newspipe-8e942f6f5695c4788328b4959527b30ff31e771d.zip |
redoing menu, sorting in place and not in python
-rw-r--r-- | src/web/js/actions/MenuActions.js | 2 | ||||
-rw-r--r-- | src/web/js/actions/MiddlePanelActions.js | 17 | ||||
-rw-r--r-- | src/web/js/components/Menu.react.js | 39 | ||||
-rw-r--r-- | src/web/js/stores/MenuStore.js | 19 | ||||
-rw-r--r-- | src/web/views/views.py | 12 |
5 files changed, 38 insertions, 51 deletions
diff --git a/src/web/js/actions/MenuActions.js b/src/web/js/actions/MenuActions.js index 4266c207..4b17d084 100644 --- a/src/web/js/actions/MenuActions.js +++ b/src/web/js/actions/MenuActions.js @@ -9,8 +9,8 @@ var MenuActions = { jquery.getJSON('/menu', function(payload) { JarrDispatcher.dispatch({ type: ActionTypes.RELOAD_MENU, + feeds: payload.feeds, categories: payload.categories, - feed_in_error: payload.feed_in_error, all_unread_count: payload.all_unread_count, }); }); diff --git a/src/web/js/actions/MiddlePanelActions.js b/src/web/js/actions/MiddlePanelActions.js index e1ced2a2..ec76d2bc 100644 --- a/src/web/js/actions/MiddlePanelActions.js +++ b/src/web/js/actions/MiddlePanelActions.js @@ -21,14 +21,16 @@ var shouldFetch = function(filters) { // } // return false; } +var key_whitelist = ['filter_id', 'filter_type', + 'query', 'search_title', 'search_content']; var reloadIfNecessaryAndDispatch = function(dispath_payload) { if(shouldFetch(dispath_payload)) { var filters = MiddlePanelStore.getRequestFilter(); - for (var key in filters) { - if(dispath_payload[key] != null) { + key_whitelist.map(function(key) { + if(key in dispath_payload) { filters[key] = dispath_payload[key]; } - } + }); jquery.getJSON('/middle_panel', filters, function(payload) { dispath_payload.articles = payload.articles; @@ -43,13 +45,8 @@ var reloadIfNecessaryAndDispatch = function(dispath_payload) { var MiddlePanelActions = { reload: function() { - var filters = MiddlePanelStore.getRequestFilter(); - jquery.getJSON('/middle_panel', filters, function(payload) { - _last_fetched_with = filters; - JarrDispatcher.dispatch({ - type: ActionTypes.RELOAD_MIDDLE_PANEL, - articles: payload.articles, - }); + reloadIfNecessaryAndDispatch({ + type: ActionTypes.RELOAD_MIDDLE_PANEL, }); }, search: function(search) { diff --git a/src/web/js/components/Menu.react.js b/src/web/js/components/Menu.react.js index 32197b3d..d0bd719d 100644 --- a/src/web/js/components/Menu.react.js +++ b/src/web/js/components/Menu.react.js @@ -132,9 +132,6 @@ var CategoryGroup = React.createClass({ </ul> ); }, - handleClick: function() { - MiddlePanelActions.setCategoryFilter(this.props.cat_id); - }, toggleFolding: function(evnt) { this.setState({unfolded: !this.state.unfolded}); evnt.stopPropagation(); @@ -185,11 +182,11 @@ var MenuFilter = React.createClass({ var Menu = React.createClass({ getInitialState: function() { - return {filter: 'all', categories: [], all_unread_count: 0, + return {filter: 'all', categories: {}, feeds: {}, active_type: null, active_id: null}; }, render: function() { - var state = this.state; + var feed_in_error = false; var rmPrntFilt = ( <ul className="nav nav-sidebar"> <Category category_id={null} @@ -199,22 +196,29 @@ var Menu = React.createClass({ </Category> </ul> ); + var categories = []; + for(var cat_id in this.state.categories) { + var feeds = []; + var unread = 0; + this.state.categories[cat_id].feeds.map(function(feed_id) { + unread += this.state.feeds[feed_id].unread; + feeds.push(this.state.feeds[feed_id]); + }.bind(this)); + categories.push(<CategoryGroup key={"c" + cat_id} feeds={feeds} + filter={this.state.filter} + active_type={this.state.active_type} + active_id={this.state.active_id} + name={this.state.categories[cat_id].name} + cat_id={this.state.categories[cat_id].id} + unread={unread} />); + } return (<Col xsHidden smHidden md={3} lg={2} data-spy="affix" id="menu" className="show-grid sidebar"> <MenuFilter filter={this.state.filter} feed_in_error={this.state.feed_in_error} /> {rmPrntFilt} - {this.state.categories.map(function(category){ - return (<CategoryGroup key={"c" + category.id} - filter={state.filter} - active_type={state.active_type} - active_id={state.active_id} - cat_id={category.id} - feeds={category.feeds} - name={category.name} - unread={category.unread} />); - })} + {categories} </Col> ); }, @@ -228,11 +232,10 @@ var Menu = React.createClass({ _onChange: function() { var datas = MenuStore.getAll(); this.setState({filter: datas.filter, + feeds: datas.feeds, categories: datas.categories, active_type: datas.active_type, - active_id: datas.active_id, - feed_in_error: datas.feed_in_error, - all_unread_count: datas.all_unread_count}); + active_id: datas.active_id}); }, }); diff --git a/src/web/js/stores/MenuStore.js b/src/web/js/stores/MenuStore.js index d98495f5..6921ae1c 100644 --- a/src/web/js/stores/MenuStore.js +++ b/src/web/js/stores/MenuStore.js @@ -6,7 +6,8 @@ var assign = require('object-assign'); var MenuStore = assign({}, EventEmitter.prototype, { - _datas: {filter: 'all', categories: [], active_type: null, active_id: null, + _datas: {filter: 'all', feeds: {}, categories: {}, + active_type: null, active_id: null, all_unread_count: 0, feed_in_error: false}, getAll: function() { return this._datas; @@ -42,6 +43,7 @@ var MenuStore = assign({}, EventEmitter.prototype, { MenuStore.dispatchToken = JarrDispatcher.register(function(action) { switch(action.type) { case ActionTypes.RELOAD_MENU: + MenuStore._datas['feeds'] = action.feeds; MenuStore._datas['categories'] = action.categories; MenuStore._datas['feed_in_error'] = action.feed_in_error; MenuStore._datas['all_unread_count'] = action.all_unread_count; @@ -65,19 +67,8 @@ MenuStore.dispatchToken = JarrDispatcher.register(function(action) { } var val = action.value_num; action.articles.map(function(article) { - for(var i in MenuStore._datas.categories) { - if(MenuStore._datas.categories[i].id == article.category_id) { - for(var j in MenuStore._datas.categories[i].feeds) { - if(MenuStore._datas.categories[i].feeds[j].id == article.feed_id) { - MenuStore._datas.categories[i].feeds[j].unread += val; - break; - - } - } - MenuStore._datas.categories[i].unread += val; - break; - } - } + MenuStore._datas.categories[article.category_id].unread += val; + MenuStore._datas.feeds[article.feed_id].unread += val; }); MenuStore.emitChange(); break; diff --git a/src/web/views/views.py b/src/web/views/views.py index 90836af1..84d1eacb 100644 --- a/src/web/views/views.py +++ b/src/web/views/views.py @@ -245,22 +245,18 @@ def get_menu(): categories = {c.id: c.dump() for c in CategoryController(g.user.id).read()} categories[0] = {'name': 'No category', 'id': 0} unread = ArticleController(g.user.id).count_by_feed(readed=False) - feed_in_error = False for cat_id in categories: categories[cat_id]['unread'] = 0 categories[cat_id]['feeds'] = [] - for feed in FeedController(g.user.id).read(): - if feed.error_count > 3: - feed_in_error = True - feed = feed.dump() + feeds = {feed.id: feed.dump() for feed in FeedController(g.user.id).read()} + for feed_id, feed in feeds.items(): feed['category_id'] = feed['category_id'] or 0 feed['unread'] = unread.get(feed['id'], 0) if feed.get('icon_url'): feed['icon_url'] = url_for('icon.icon', url=feed['icon_url']) categories[feed['category_id']]['unread'] += feed['unread'] - categories[feed['category_id']]['feeds'].append(feed) - return jsonify(**{'categories': list(categories.values()), - 'feed_in_error': feed_in_error, + categories[feed['category_id']]['feeds'].append(feed_id) + return jsonify(**{'feeds': feeds, 'categories': categories, 'all_unread_count': sum(unread.values())}) |