From 15c4ed6bebdeb277c24bd92dab5bba900fc90de4 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Mon, 25 Jan 2016 13:14:06 +0100 Subject: redoing constant, handling read / unread in menu, removing bad optim for loading articles --- src/web/js/actions/MenuActions.js | 10 +++--- src/web/js/actions/MiddlePanelActions.js | 57 +++++++++++++++++--------------- src/web/js/actions/RightPanelActions.js | 4 +-- 3 files changed, 38 insertions(+), 33 deletions(-) (limited to 'src/web/js/actions') diff --git a/src/web/js/actions/MenuActions.js b/src/web/js/actions/MenuActions.js index 1f1eea01..bf039fd1 100644 --- a/src/web/js/actions/MenuActions.js +++ b/src/web/js/actions/MenuActions.js @@ -1,5 +1,5 @@ var JarrDispatcher = require('../dispatcher/JarrDispatcher'); -var MenuActionTypes = require('../constants/JarrConstants').MenuActionTypes; +var ActionTypes = require('../constants/JarrConstants'); var jquery = require('jquery'); @@ -8,7 +8,7 @@ var MenuActions = { reload: function() { jquery.getJSON('/menu', function(payload) { JarrDispatcher.dispatch({ - type: MenuActionTypes.RELOAD_MENU, + type: ActionTypes.RELOAD_MENU, categories: payload.categories, feed_in_error: payload.feed_in_error, all_unread_count: payload.all_unread_count, @@ -17,19 +17,19 @@ var MenuActions = { }, setFilterAll: function() { JarrDispatcher.dispatch({ - type: MenuActionTypes.MENU_FILTER, + type: ActionTypes.MENU_FILTER, filter: 'all', }); }, setFilterUnread: function() { JarrDispatcher.dispatch({ - type: MenuActionTypes.MENU_FILTER, + type: ActionTypes.MENU_FILTER, filter: 'unread', }); }, setFilterError: function() { JarrDispatcher.dispatch({ - type: MenuActionTypes.MENU_FILTER, + type: ActionTypes.MENU_FILTER, filter: 'error', }); }, diff --git a/src/web/js/actions/MiddlePanelActions.js b/src/web/js/actions/MiddlePanelActions.js index 7a944ecd..7c956e85 100644 --- a/src/web/js/actions/MiddlePanelActions.js +++ b/src/web/js/actions/MiddlePanelActions.js @@ -1,24 +1,25 @@ var JarrDispatcher = require('../dispatcher/JarrDispatcher'); -var MiddlePanelActionTypes = require('../constants/JarrConstants').MiddlePanelActionTypes; +var ActionTypes = require('../constants/JarrConstants'); 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; + 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)) { @@ -46,59 +47,61 @@ var MiddlePanelActions = { jquery.getJSON('/middle_panel', filters, function(payload) { _last_fetched_with = filters; JarrDispatcher.dispatch({ - type: MiddlePanelActionTypes.RELOAD_MIDDLE_PANEL, + type: ActionTypes.RELOAD_MIDDLE_PANEL, articles: payload.articles, }); }); }, removeParentFilter: function() { reloadIfNecessaryAndDispatch({ - type: MiddlePanelActionTypes.PARENT_FILTER, + type: ActionTypes.PARENT_FILTER, filter_type: null, filter_id: null, }); }, setCategoryFilter: function(category_id) { reloadIfNecessaryAndDispatch({ - type: MiddlePanelActionTypes.PARENT_FILTER, + type: ActionTypes.PARENT_FILTER, filter_type: 'category_id', filter_id: category_id, }); }, setFeedFilter: function(feed_id) { reloadIfNecessaryAndDispatch({ - type: MiddlePanelActionTypes.PARENT_FILTER, + type: ActionTypes.PARENT_FILTER, filter_type: 'feed_id', filter_id: feed_id, }); }, setFilterAll: function() { reloadIfNecessaryAndDispatch({ - type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER, + type: ActionTypes.MIDDLE_PANEL_FILTER, filter: 'all', }); }, setFilterUnread: function() { reloadIfNecessaryAndDispatch({ - type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER, + type: ActionTypes.MIDDLE_PANEL_FILTER, filter: 'unread', }); }, setFilterLiked: function() { reloadIfNecessaryAndDispatch({ - type: MiddlePanelActionTypes.MIDDLE_PANEL_FILTER, + type: ActionTypes.MIDDLE_PANEL_FILTER, filter: 'liked', }); }, - changeRead: function(article_id, new_value){ + changeRead: function(category_id, feed_id, article_id, new_value){ jquery.ajax({type: 'PUT', contentType: 'application/json', data: JSON.stringify({readed: new_value}), url: "api/v2.0/article/" + article_id, success: function (result) { JarrDispatcher.dispatch({ - type: MiddlePanelActionTypes.CHANGE_ATTR, + type: ActionTypes.CHANGE_ATTR, article_id: article_id, + category_id: category_id, + feed_id: feed_id, attribute: 'read', value: new_value, }); @@ -108,15 +111,17 @@ var MiddlePanelActions = { }, }); }, - changeLike: function(article_id, new_value){ + changeLike: function(category_id, feed_id, article_id, new_value){ jquery.ajax({type: 'PUT', contentType: 'application/json', data: JSON.stringify({like: new_value}), url: "api/v2.0/article/" + article_id, success: function (result) { JarrDispatcher.dispatch({ - type: MiddlePanelActionTypes.CHANGE_ATTR, + type: ActionTypes.CHANGE_ATTR, article_id: article_id, + category_id: category_id, + feed_id: feed_id, attribute: 'liked', value: new_value, }); diff --git a/src/web/js/actions/RightPanelActions.js b/src/web/js/actions/RightPanelActions.js index 3cd549e5..7a7b935a 100644 --- a/src/web/js/actions/RightPanelActions.js +++ b/src/web/js/actions/RightPanelActions.js @@ -1,5 +1,5 @@ var JarrDispatcher = require('../dispatcher/JarrDispatcher'); -var RightActionTypes = require('../constants/JarrConstants').RightPanelActionTypes; +var ActionTypes = require('../constants/JarrConstants'); var jquery = require('jquery'); var RightPanelStore = require('../stores/RightPanelStore'); @@ -10,7 +10,7 @@ var RightPanelActions = { jquery.getJSON('api/v2.0/' + obj_type + '/' + obj_id, function(payload) { _last_fetched_with = filters; JarrDispatcher.dispatch({ - type: RightPanelActionTypes.LOAD_RIGHT_PANEL, + type: ActionTypes.LOAD_RIGHT_PANEL, articles: payload.articles, }); }); -- cgit