aboutsummaryrefslogtreecommitdiff
path: root/src/web/js/stores
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2016-01-23 03:21:41 +0100
committerFrançois Schmidts <francois.schmidts@gmail.com>2016-01-26 23:47:09 +0100
commit94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851 (patch)
treea5d3597db4c9c2af5062aba5270625776e6ee4cb /src/web/js/stores
parentdisplaying error (diff)
downloadnewspipe-94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851.tar.gz
newspipe-94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851.tar.bz2
newspipe-94a18fbdecaa798d67a5bf7ad0f2b8ee4e0c7851.zip
meh, kinda works, sleep now
Diffstat (limited to 'src/web/js/stores')
-rw-r--r--src/web/js/stores/MiddlePanelStore.js72
1 files changed, 40 insertions, 32 deletions
diff --git a/src/web/js/stores/MiddlePanelStore.js b/src/web/js/stores/MiddlePanelStore.js
index 4e6e04c4..80ac8198 100644
--- a/src/web/js/stores/MiddlePanelStore.js
+++ b/src/web/js/stores/MiddlePanelStore.js
@@ -7,38 +7,51 @@ var assign = require('object-assign');
var MiddlePanelStore = assign({}, EventEmitter.prototype, {
_datas: {filter: 'unread', articles: [],
- parent_filter_type: null, parent_filter_id: null},
+ filter_type: null, filter_id: null},
getAll: function() {
return this._datas;
},
+ getRequestFilter: function() {
+ return {'filter': this._datas.filter,
+ 'filter_type': this._datas.filter_type,
+ 'filter_id': this._datas.filter_id};
+ },
getArticles: function() {
- var articles = [];
var key = null;
var id = null;
- if (this._datas.parent_filter_type) {
- key = this._datas.parent_filter_type + '_id';
- id = this._datas.parent_filter_id;
+ var filter = this._datas.filter;
+ if (this._datas.filter_type) {
+ key = this._datas.filter_type + '_id';
+ id = this._datas.filter_id;
}
- this._datas.articles.map(function(article) {
- if(!key || article[key] == id) {
- articles.push(article);
- }
+ return this._datas.articles.filter(function(article) {
+ return ((!key || article[key] == id)
+ && (filter == 'all'
+ || (filter == 'unread' && !article.read)
+ || (filter == 'liked' && article.liked)));
});
- return articles;
+ },
+ setArticles: function(articles) {
+ if(articles || articles == []) {
+ this._datas.articles = articles;
+ return true;
+ }
+ return false;
},
setFilter: function(value) {
if(this._datas.filter != value) {
this._datas.filter = value;
- this.emitChange();
+ return true;
}
+ return false;
},
setParentFilter: function(type, value) {
- if(this._datas['parent_filter_id'] != value
- || this._datas['parent_filter_type'] != type) {
- this._datas['parent_filter_type'] = type;
- this._datas['parent_filter_id'] = value;
- this.emitChange();
+ if(this._datas.filter_id != value || this._datas.filter_type != type) {
+ this._datas.filter_type = type;
+ this._datas.filter_id = value;
+ return true;
}
+ return false;
},
emitChange: function() {
this.emit(CHANGE_EVENT);
@@ -53,30 +66,25 @@ var MiddlePanelStore = assign({}, EventEmitter.prototype, {
MiddlePanelStore.dispatchToken = JarrDispatcher.register(function(action) {
+ var changed = false;
switch(action.type) {
case MiddlePanelActionTypes.RELOAD_MIDDLE_PANEL:
- MiddlePanelStore._datas['articles'] = action.articles;
+ MiddlePanelStore.setArticles(action.articles);
MiddlePanelStore.emitChange();
break;
- // PARENT FILTER
case MiddlePanelActionTypes.MIDDLE_PANEL_PARENT_FILTER:
- MiddlePanelStore.setParentFilter(action.parent_type,
- action.parent_id);
- break;
- // FILTER
- case MiddlePanelActionTypes.MIDDLE_PANEL_FILTER_ALL:
- MiddlePanelStore.setFilter('all');
+ changed = MiddlePanelStore.setParentFilter(action.filter_type,
+ action.filter_id);
+ changed = MiddlePanelStore.setArticles(action.articles) || changed;
+ if(changed) {MiddlePanelStore.emitChange();}
break;
- case MiddlePanelActionTypes.MIDDLE_PANEL_FILTER_UNREAD:
- MiddlePanelStore.setFilter('unread');
+ case MiddlePanelActionTypes.MIDDLE_PANEL_FILTER:
+ changed = MiddlePanelStore.setFilter(action.filter);
+ changed = MiddlePanelStore.setArticles(action.articles) || changed;
+ if(changed) {MiddlePanelStore.emitChange();}
break;
- case MiddlePanelActionTypes.MIDDLE_PANEL_FILTER_LIKED:
- MiddlePanelStore.setFilter('liked');
- break;
-
-
default:
- // do nothing
+ // pass
}
});
bgstack15