diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2016-01-23 03:21:41 +0100 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-01-26 23:47:09 +0100 |
commit | 94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851 (patch) | |
tree | a5d3597db4c9c2af5062aba5270625776e6ee4cb /src/web/js/actions | |
parent | displaying error (diff) | |
download | newspipe-94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851.tar.gz newspipe-94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851.tar.bz2 newspipe-94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851.zip |
meh, kinda works, sleep now
Diffstat (limited to 'src/web/js/actions')
-rw-r--r-- | src/web/js/actions/MiddlePanelActions.js | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/src/web/js/actions/MiddlePanelActions.js b/src/web/js/actions/MiddlePanelActions.js index f750c900..159ba91b 100644 --- a/src/web/js/actions/MiddlePanelActions.js +++ b/src/web/js/actions/MiddlePanelActions.js @@ -1,53 +1,92 @@ var JarrDispatcher = require('../dispatcher/JarrDispatcher'); var MiddlePanelActionTypes = require('../constants/JarrConstants').MiddlePanelActionTypes; var jquery = require('jquery'); +var MiddlePanelStore = require('../stores/MiddlePanelStore'); + +var _last_fetched_with = {}; +var shouldFetch = function(filters) { + if(filters.filter != null // undefined means unchanged + && (_last_fetched_with.filter != 'all' + || _last_fetched_with.filter != filters.filter)) { + return true; + } + if(_last_fetched_with.filter_type != null) { + if(_last_fetched_with.filter_type != filters.filter_type) { + return true; + } + if(_last_fetched_with.filter_id != filters.filter_id) { + return true; + } + } + return false; +} +var reloadIfNecessaryAndDispatch = function(dispath_payload) { + if(shouldFetch(dispath_payload)) { + filters = MiddlePanelStore.getRequestFilter(); + for (var key in filters) { + if(dispath_payload[key] != null) { + filters[key] = dispath_payload[key]; + } + } + jquery.getJSON('/middle_panel', dispath_payload, function(payload) { + dispath_payload.articles = payload.articles; + JarrDispatcher.dispatch(dispath_payload); + _last_fetched_with = MiddlePanelStore.getRequestFilter(); + }); + } else { + JarrDispatcher.dispatch(dispath_payload); + } +} var MiddlePanelActions = { reload: function() { - jquery.getJSON('/middle_panel', function(payload) { + filters = MiddlePanelStore.getRequestFilter(); + jquery.getJSON('/middle_panel', filters, function(payload) { + _last_fetched_with = filters; JarrDispatcher.dispatch({ type: MiddlePanelActionTypes.RELOAD_MIDDLE_PANEL, articles: payload.articles, }); }); }, - removeParentFilter: function(parent_type, parent_id) { - JarrDispatcher.dispatch({ + removeParentFilter: function(filter_type, filter_id) { + reloadIfNecessaryAndDispatch({ type: MiddlePanelActionTypes.MIDDLE_PANEL_PARENT_FILTER, - parent_type: null, - parent_id: null, + filter_type: null, + filter_id: null, }); }, setCategoryFilter: function(category_id) { - JarrDispatcher.dispatch({ + reloadIfNecessaryAndDispatch({ type: MiddlePanelActionTypes.MIDDLE_PANEL_PARENT_FILTER, - parent_type: 'category', - parent_id: category_id, + filter_type: 'category', + filter_id: category_id, }); }, setFeedFilter: function(feed_id) { - JarrDispatcher.dispatch({ + reloadIfNecessaryAndDispatch({ type: MiddlePanelActionTypes.MIDDLE_PANEL_PARENT_FILTER, - parent_type: 'feed', - parent_id: feed_id, + filter_type: 'feed', + filter_id: feed_id, }); }, setFilterAll: function() { - JarrDispatcher.dispatch({ - component: 'middle_panel', - type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER_ALL, + reloadIfNecessaryAndDispatch({ + type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER, + filter: 'all', }); }, setFilterUnread: function() { - JarrDispatcher.dispatch({ - component: 'middle_panel', - type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER_UNREAD, + reloadIfNecessaryAndDispatch({ + type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER, + filter: 'unread', }); }, setFilterLiked: function() { - JarrDispatcher.dispatch({ - type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER_LIKED, + reloadIfNecessaryAndDispatch({ + type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER, + filter: 'liked', }); }, }; |