diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2016-01-26 23:23:42 +0100 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-01-27 00:34:34 +0100 |
commit | f3578d10239ffa716450c0089bcbc8d2826f59fd (patch) | |
tree | dd5a35e6ac3b953bd00f635c0db106e5081570d5 /src/web/js | |
parent | optim on filter, not rerendering (diff) | |
download | newspipe-f3578d10239ffa716450c0089bcbc8d2826f59fd.tar.gz newspipe-f3578d10239ffa716450c0089bcbc8d2826f59fd.tar.bz2 newspipe-f3578d10239ffa716450c0089bcbc8d2826f59fd.zip |
mark all as read button
Diffstat (limited to 'src/web/js')
-rw-r--r-- | src/web/js/actions/MiddlePanelActions.js | 45 | ||||
-rw-r--r-- | src/web/js/components/MiddlePanel.react.js | 4 | ||||
-rw-r--r-- | src/web/js/stores/MenuStore.js | 30 | ||||
-rw-r--r-- | src/web/js/stores/MiddlePanelStore.js | 23 |
4 files changed, 58 insertions, 44 deletions
diff --git a/src/web/js/actions/MiddlePanelActions.js b/src/web/js/actions/MiddlePanelActions.js index 47a9958c..ab54217e 100644 --- a/src/web/js/actions/MiddlePanelActions.js +++ b/src/web/js/actions/MiddlePanelActions.js @@ -43,7 +43,7 @@ var reloadIfNecessaryAndDispatch = function(dispath_payload) { var MiddlePanelActions = { reload: function() { - filters = MiddlePanelStore.getRequestFilter(); + var filters = MiddlePanelStore.getRequestFilter(); jquery.getJSON('/middle_panel', filters, function(payload) { _last_fetched_with = filters; JarrDispatcher.dispatch({ @@ -84,19 +84,17 @@ var MiddlePanelActions = { contentType: 'application/json', data: JSON.stringify({readed: new_value}), url: "api/v2.0/article/" + article_id, - success: function (result) { + success: function () { JarrDispatcher.dispatch({ type: ActionTypes.CHANGE_ATTR, - article_id: article_id, - category_id: category_id, - feed_id: feed_id, attribute: 'read', - value: new_value, + value_bool: new_value, + value_num: new_value ? -1 : 1, + articles: [{article_id: article_id, + category_id: category_id, + feed_id: feed_id}], }); }, - error: function(XMLHttpRequest, textStatus, errorThrown){ - console.log(XMLHttpRequest.responseText); - }, }); }, changeLike: function(category_id, feed_id, article_id, new_value){ @@ -104,18 +102,33 @@ var MiddlePanelActions = { contentType: 'application/json', data: JSON.stringify({like: new_value}), url: "api/v2.0/article/" + article_id, - success: function (result) { + success: function () { JarrDispatcher.dispatch({ type: ActionTypes.CHANGE_ATTR, - article_id: article_id, - category_id: category_id, - feed_id: feed_id, attribute: 'liked', - value: new_value, + value_bool: new_value, + value_num: new_value ? -1 : 1, + articles: [{article_id: article_id, + category_id: category_id, + feed_id: feed_id}], }); }, - error: function(XMLHttpRequest, textStatus, errorThrown){ - console.log(XMLHttpRequest.responseText); + }); + }, + markAllAsRead: function() { + var filters = MiddlePanelStore.getRequestFilter(); + jquery.ajax({type: 'PUT', + contentType: 'application/json', + data: JSON.stringify(filters), + url: "/mark_all_as_read", + success: function (payload) { + JarrDispatcher.dispatch({ + type: ActionTypes.CHANGE_ATTR, + attribute: 'read', + value_num: -1, + value_bool: true, + articles: payload.articles, + }); }, }); }, diff --git a/src/web/js/components/MiddlePanel.react.js b/src/web/js/components/MiddlePanel.react.js index e0ea8110..756a811b 100644 --- a/src/web/js/components/MiddlePanel.react.js +++ b/src/web/js/components/MiddlePanel.react.js @@ -73,6 +73,10 @@ var MiddlePanelFilter = React.createClass({ onMouseDown={() => this.setFilter("liked")} bsSize="small">Liked</Button> </ButtonGroup> + <ButtonGroup> + <Button onMouseDown={MiddlePanelActions.markAllAsRead} + bsSize="small">Mark all as read</Button> + </ButtonGroup> </Row> ); }, diff --git a/src/web/js/stores/MenuStore.js b/src/web/js/stores/MenuStore.js index ecf32499..d98495f5 100644 --- a/src/web/js/stores/MenuStore.js +++ b/src/web/js/stores/MenuStore.js @@ -63,27 +63,23 @@ MenuStore.dispatchToken = JarrDispatcher.register(function(action) { if(action.attribute != 'read') { return; } - for(var i in MenuStore._datas.categories) { - if(MenuStore._datas.categories[i].id == action.category_id) { - for(var j in MenuStore._datas.categories[i].feeds) { - if(MenuStore._datas.categories[i].feeds[j].id == action.feed_id) { - if(action.value) { - MenuStore._datas.categories[i].feeds[j].unread -= 1; - } else { - MenuStore._datas.categories[i].feeds[j].unread += 1; - } + 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; } - if(action.value) { - MenuStore._datas.categories[i].unread -= 1; - } else { - MenuStore._datas.categories[i].unread += 1; - } - MenuStore.emitChange(); - break; } - } + }); + MenuStore.emitChange(); break; default: // do nothing diff --git a/src/web/js/stores/MiddlePanelStore.js b/src/web/js/stores/MiddlePanelStore.js index 12c2d6e8..bc7cee51 100644 --- a/src/web/js/stores/MiddlePanelStore.js +++ b/src/web/js/stores/MiddlePanelStore.js @@ -84,21 +84,22 @@ MiddlePanelStore.dispatchToken = JarrDispatcher.register(function(action) { if(changed) {MiddlePanelStore.emitChange();} break; case ActionTypes.CHANGE_ATTR: - var id = action.article_id; var attr = action.attribute; - var val = action.value; - for (var i in MiddlePanelStore._datas.articles) { - if(MiddlePanelStore._datas.articles[i].article_id == id) { - if (MiddlePanelStore._datas.articles[i][attr] != val) { - MiddlePanelStore._datas.articles[i][attr] = val; - // avoiding redraw if not filter, display won't change anyway - if(MiddlePanelStore._datas.filter != 'all') { - MiddlePanelStore.emitChange(); + var val = action.value_bool; + action.articles.map(function(article) { + for (var i in MiddlePanelStore._datas.articles) { + if(MiddlePanelStore._datas.articles[i].article_id == article.article_id) { + if (MiddlePanelStore._datas.articles[i][attr] != val) { + MiddlePanelStore._datas.articles[i][attr] = val; + // avoiding redraw if not filter, display won't change anyway + if(MiddlePanelStore._datas.filter != 'all') { + MiddlePanelStore.emitChange(); + } } + break; } - break; } - } + }); break; default: // pass |