aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/web')
-rw-r--r--src/web/js/actions/MiddlePanelActions.js75
1 files changed, 28 insertions, 47 deletions
diff --git a/src/web/js/actions/MiddlePanelActions.js b/src/web/js/actions/MiddlePanelActions.js
index 3704e7ec..b31e73e0 100644
--- a/src/web/js/actions/MiddlePanelActions.js
+++ b/src/web/js/actions/MiddlePanelActions.js
@@ -4,59 +4,40 @@ var jquery = require('jquery');
var MiddlePanelStore = require('../stores/MiddlePanelStore');
var _last_fetched_with = {};
-var shouldFetch = function(filters) {
- return true; // FIXME disabling intelligent fetch for now, no caching better that bad one
-// 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)) {
- var filters = MiddlePanelStore.getRequestFilter(
- dispath_payload.display_search);
- MiddlePanelStore.filter_whitelist.map(function(key) {
- if(key in dispath_payload) {
- filters[key] = dispath_payload[key];
- }
- if(filters[key] == null) {
- delete filters[key];
- }
- });
- if('display_search' in filters) {
- delete filters['display_search'];
+
+var reloadAndDispatch = function(dispath_payload) {
+ var filters = MiddlePanelStore.getRequestFilter(
+ dispath_payload.display_search);
+ MiddlePanelStore.filter_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;
- dispath_payload.filters = filters;
- JarrDispatcher.dispatch(dispath_payload);
- _last_fetched_with = MiddlePanelStore.getRequestFilter();
- });
- } else {
- JarrDispatcher.dispatch(dispath_payload);
+ if(filters[key] == null) {
+ delete filters[key];
+ }
+ });
+ if('display_search' in filters) {
+ delete filters['display_search'];
}
+ jquery.getJSON('/middle_panel', filters,
+ function(payload) {
+ console.log(payload);
+ dispath_payload.articles = payload.articles;
+ dispath_payload.filters = filters;
+ JarrDispatcher.dispatch(dispath_payload);
+ _last_fetched_with = MiddlePanelStore.getRequestFilter();
+ });
}
var MiddlePanelActions = {
reload: function() {
- reloadIfNecessaryAndDispatch({
+ reloadAndDispatch({
type: ActionTypes.RELOAD_MIDDLE_PANEL,
});
},
search: function(search) {
- reloadIfNecessaryAndDispatch({
+ reloadAndDispatch({
type: ActionTypes.RELOAD_MIDDLE_PANEL,
display_search: true,
query: search.query,
@@ -65,34 +46,34 @@ var MiddlePanelActions = {
});
},
search_off: function() {
- reloadIfNecessaryAndDispatch({
+ reloadAndDispatch({
type: ActionTypes.RELOAD_MIDDLE_PANEL,
display_search: false,
});
},
removeParentFilter: function() {
- reloadIfNecessaryAndDispatch({
+ reloadAndDispatch({
type: ActionTypes.PARENT_FILTER,
filter_type: null,
filter_id: null,
});
},
setCategoryFilter: function(category_id) {
- reloadIfNecessaryAndDispatch({
+ reloadAndDispatch({
type: ActionTypes.PARENT_FILTER,
filter_type: 'category_id',
filter_id: category_id,
});
},
setFeedFilter: function(feed_id) {
- reloadIfNecessaryAndDispatch({
+ reloadAndDispatch({
type: ActionTypes.PARENT_FILTER,
filter_type: 'feed_id',
filter_id: feed_id,
});
},
setFilter: function(filter) {
- reloadIfNecessaryAndDispatch({
+ reloadAndDispatch({
type: ActionTypes.MIDDLE_PANEL_FILTER,
filter: filter,
});
bgstack15