aboutsummaryrefslogtreecommitdiff
path: root/src/web/js/stores
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2020-02-26 11:27:31 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2020-02-26 11:27:31 +0100
commit62b3afeeedfe054345f86093e2d243e956c1e3c9 (patch)
treebbd58f5c8c07f5d87b1c1cca73fa1d5af6178f48 /src/web/js/stores
parentUpdated Python dependencies. (diff)
downloadnewspipe-62b3afeeedfe054345f86093e2d243e956c1e3c9.tar.gz
newspipe-62b3afeeedfe054345f86093e2d243e956c1e3c9.tar.bz2
newspipe-62b3afeeedfe054345f86093e2d243e956c1e3c9.zip
The project is now using Poetry.
Diffstat (limited to 'src/web/js/stores')
-rw-r--r--src/web/js/stores/MenuStore.js135
-rw-r--r--src/web/js/stores/MiddlePanelStore.js126
-rw-r--r--src/web/js/stores/RightPanelStore.js77
-rw-r--r--src/web/js/stores/__tests__/TodoStore-test.js90
4 files changed, 0 insertions, 428 deletions
diff --git a/src/web/js/stores/MenuStore.js b/src/web/js/stores/MenuStore.js
deleted file mode 100644
index 770bc501..00000000
--- a/src/web/js/stores/MenuStore.js
+++ /dev/null
@@ -1,135 +0,0 @@
-var JarrDispatcher = require('../dispatcher/JarrDispatcher');
-var ActionTypes = require('../constants/JarrConstants');
-var EventEmitter = require('events').EventEmitter;
-var CHANGE_EVENT = 'change_menu';
-var assign = require('object-assign');
-
-
-var MenuStore = assign({}, EventEmitter.prototype, {
- _datas: {filter: 'unread', feeds: {}, categories: {}, categories_order: [],
- active_type: null, active_id: null,
- is_admin: false, crawling_method: 'default',
- all_unread_count: 0, max_error: 0, error_threshold: 0,
- all_folded: false},
- getAll: function() {
- return this._datas;
- },
- setFilter: function(value) {
- if(this._datas.filter != value) {
- this._datas.filter = value;
- this._datas.all_folded = null;
- this.emitChange();
- }
- },
- setActive: function(type, value) {
- if(this._datas.active_id != value || this._datas.active_type != type) {
- this._datas.active_type = type;
- this._datas.active_id = value;
- this._datas.all_folded = null;
- this.emitChange();
- }
- },
- emitChange: function() {
- this.emit(CHANGE_EVENT);
- },
- addChangeListener: function(callback) {
- this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT, callback);
- },
-});
-
-
-MenuStore.dispatchToken = JarrDispatcher.register(function(action) {
- switch(action.type) {
- case ActionTypes.RELOAD_MENU:
- MenuStore._datas['feeds'] = action.feeds;
- MenuStore._datas['categories'] = action.categories;
- MenuStore._datas['categories_order'] = action.categories_order;
- MenuStore._datas['is_admin'] = action.is_admin;
- MenuStore._datas['max_error'] = action.max_error;
- MenuStore._datas['error_threshold'] = action.error_threshold;
- MenuStore._datas['crawling_method'] = action.crawling_method;
- MenuStore._datas['all_unread_count'] = action.all_unread_count;
- MenuStore._datas.all_folded = null;
- MenuStore.emitChange();
- break;
- case ActionTypes.PARENT_FILTER:
- MenuStore.setActive(action.filter_type, action.filter_id);
- if(action.filters && action.articles && !action.filters.query
- && action.filters.filter == 'unread') {
- var new_unread = {};
- action.articles.map(function(article) {
- if(!(article.feed_id in new_unread)) {
- new_unread[article.feed_id] = 0;
- }
- if(!article.read) {
- new_unread[article.feed_id] += 1;
- }
- });
- var changed = false;
- for(var feed_id in new_unread) {
- var old_unread = MenuStore._datas.feeds[feed_id].unread;
- if(old_unread == new_unread[feed_id]) {
- continue;
- }
- changed = true;
- MenuStore._datas.feeds[feed_id].unread = new_unread[feed_id];
- var cat_id = MenuStore._datas.feeds[feed_id].category_id;
- MenuStore._datas.categories[cat_id].unread -= old_unread;
- MenuStore._datas.categories[cat_id].unread += new_unread[feed_id];
- }
- if(changed) {
- MenuStore._datas.all_folded = null;
- MenuStore.emitChange();
- }
- }
- break;
- case ActionTypes.MENU_FILTER:
- MenuStore.setFilter(action.filter);
- break;
- case ActionTypes.CHANGE_ATTR:
- if(action.attribute != 'read') {
- return;
- }
- var val = action.value_num;
- action.articles.map(function(article) {
- MenuStore._datas.categories[article.category_id].unread += val;
- MenuStore._datas.feeds[article.feed_id].unread += val;
- });
- MenuStore._datas.all_folded = null;
- MenuStore.emitChange();
- break;
- case ActionTypes.LOAD_ARTICLE:
- if(!action.was_read_before) {
- MenuStore._datas.categories[action.article.category_id].unread -= 1;
- MenuStore._datas.feeds[action.article.feed_id].unread -= 1;
- MenuStore._datas.all_folded = null;
- MenuStore.emitChange();
- }
- break;
- case ActionTypes.TOGGLE_MENU_FOLD:
- MenuStore._datas.all_folded = action.all_folded;
- MenuStore.emitChange();
- break;
- case ActionTypes.MARK_ALL_AS_READ:
- action.articles.map(function(art) {
- if(!art.read) {
- MenuStore._datas.feeds[art.feed_id].unread -= 1;
- if(art.category_id) {
- MenuStore._datas.categories[art.category_id].unread -= 1;
-
- }
- }
- });
-
- MenuStore._datas.all_folded = null;
- MenuStore.emitChange();
- break;
- default:
- // do nothing
- }
-});
-
-module.exports = MenuStore;
diff --git a/src/web/js/stores/MiddlePanelStore.js b/src/web/js/stores/MiddlePanelStore.js
deleted file mode 100644
index c554f929..00000000
--- a/src/web/js/stores/MiddlePanelStore.js
+++ /dev/null
@@ -1,126 +0,0 @@
-var JarrDispatcher = require('../dispatcher/JarrDispatcher');
-var ActionTypes = require('../constants/JarrConstants');
-var EventEmitter = require('events').EventEmitter;
-var CHANGE_EVENT = 'change_middle_panel';
-var assign = require('object-assign');
-
-
-var MiddlePanelStore = assign({}, EventEmitter.prototype, {
- filter_whitelist: ['filter', 'filter_id', 'filter_type', 'display_search',
- 'query', 'search_title', 'search_content'],
- _datas: {articles: [], selected_article: null,
- filter: 'unread', filter_type: null, filter_id: null,
- display_search: false, query: null,
- search_title: true, search_content: false},
- getAll: function() {
- return this._datas;
- },
- getRequestFilter: function(display_search) {
- var filters = {'filter': this._datas.filter,
- 'filter_type': this._datas.filter_type,
- 'filter_id': this._datas.filter_id,
- };
- if(display_search || (display_search == undefined && this._datas.display_search)) {
- filters.query = this._datas.query;
- filters.search_title = this._datas.search_title;
- filters.search_content = this._datas.search_content;
- };
- return filters;
- },
- getArticles: function() {
- var key = null;
- var id = null;
- if (this._datas.filter_type) {
- key = this._datas.filter_type;
- id = this._datas.filter_id;
- }
- return this._datas.articles
- .map(function(article) {
- if(article.article_id == this._datas.selected_article) {
- article.selected = true;
- } else if(article.selected) {
- article.selected = false;
- }
- return article;
- }.bind(this))
- .filter(function(article) {
- return (article.selected || ((!key || article[key] == id)
- && (this._datas.filter == 'all'
- || (this._datas.filter == 'unread' && !article.read)
- || (this._datas.filter == 'liked' && article.liked))));
- }.bind(this));
-
- },
- setArticles: function(articles) {
- if(articles || articles == []) {
- this._datas.articles = articles;
- return true;
- }
- return false;
- },
- registerFilter: function(action) {
- var changed = false;
- this.filter_whitelist.map(function(key) {
- if(key in action && this._datas[key] != action[key]) {
- changed = true;
- this._datas[key] = action[key];
- }
- }.bind(this));
- return changed;
- },
- emitChange: function() {
- this.emit(CHANGE_EVENT);
- },
- addChangeListener: function(callback) {
- this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT, callback);
- },
-});
-
-
-MiddlePanelStore.dispatchToken = JarrDispatcher.register(function(action) {
- var changed = false;
- if (action.type == ActionTypes.RELOAD_MIDDLE_PANEL
- || action.type == ActionTypes.PARENT_FILTER
- || action.type == ActionTypes.MIDDLE_PANEL_FILTER) {
- changed = MiddlePanelStore.registerFilter(action);
- changed = MiddlePanelStore.setArticles(action.articles) || changed;
- } else if (action.type == ActionTypes.MARK_ALL_AS_READ) {
- changed = MiddlePanelStore.registerFilter(action);
- for(var i in action.articles) {
- action.articles[i].read = true;
- }
- changed = MiddlePanelStore.setArticles(action.articles) || changed;
- } else if (action.type == ActionTypes.CHANGE_ATTR) {
- var attr = action.attribute;
- 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') {
- changed = true;
- }
- }
- break;
- }
- }
- });
- } else if (action.type == ActionTypes.LOAD_ARTICLE) {
- changed = true;
- MiddlePanelStore._datas.selected_article = action.article.id;
- for (var i in MiddlePanelStore._datas.articles) {
- if(MiddlePanelStore._datas.articles[i].article_id == action.article.id) {
- MiddlePanelStore._datas.articles[i].read = true;
- break;
- }
- }
- }
- if(changed) {MiddlePanelStore.emitChange();}
-});
-
-module.exports = MiddlePanelStore;
diff --git a/src/web/js/stores/RightPanelStore.js b/src/web/js/stores/RightPanelStore.js
deleted file mode 100644
index 6c268dfd..00000000
--- a/src/web/js/stores/RightPanelStore.js
+++ /dev/null
@@ -1,77 +0,0 @@
-var JarrDispatcher = require('../dispatcher/JarrDispatcher');
-var ActionTypes = require('../constants/JarrConstants');
-var EventEmitter = require('events').EventEmitter;
-var CHANGE_EVENT = 'change_middle_panel';
-var assign = require('object-assign');
-var MenuStore = require('../stores/MenuStore');
-
-
-var RightPanelStore = assign({}, EventEmitter.prototype, {
- category: null,
- feed: null,
- article: null,
- current: null,
- getAll: function() {
- return {category: this.category, feed: this.feed,
- article: this.article, current: this.current};
- },
- emitChange: function() {
- this.emit(CHANGE_EVENT);
- },
- addChangeListener: function(callback) {
- this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT, callback);
- },
-});
-
-
-RightPanelStore.dispatchToken = JarrDispatcher.register(function(action) {
- switch(action.type) {
- case ActionTypes.PARENT_FILTER:
- RightPanelStore.article = null;
- if(action.filter_id == null) {
- RightPanelStore.category = null;
- RightPanelStore.feed = null;
- RightPanelStore.current = null;
- } else if(action.filter_type == 'category_id') {
- RightPanelStore.category = MenuStore._datas.categories[action.filter_id];
- RightPanelStore.feed = null;
- RightPanelStore.current = 'category';
- RightPanelStore.emitChange();
- } else {
-
- RightPanelStore.feed = MenuStore._datas.feeds[action.filter_id];
- RightPanelStore.category = MenuStore._datas.categories[RightPanelStore.feed.category_id];
- RightPanelStore.current = 'feed';
- RightPanelStore.emitChange();
- }
- break;
- case ActionTypes.LOAD_ARTICLE:
- RightPanelStore.feed = MenuStore._datas.feeds[action.article.feed_id];
- RightPanelStore.category = MenuStore._datas.categories[action.article.category_id];
- RightPanelStore.article = action.article;
- RightPanelStore.current = 'article';
- RightPanelStore.emitChange();
- break;
- case ActionTypes.RELOAD_MENU:
- RightPanelStore.article = null;
- if(RightPanelStore.category && !(RightPanelStore.category.id.toString() in action.categories)) {
- RightPanelStore.category = null;
- RightPanelStore.current = null;
- }
- if(RightPanelStore.feed && !(RightPanelStore.feed.id.toString() in action.feeds)) {
- RightPanelStore.feed = null;
- RightPanelStore.current = null;
- }
- if(RightPanelStore.current == 'article') {
- RightPanelStore.current = null;
- }
- RightPanelStore.emitChange();
- default:
- // pass
- }
-});
-
-module.exports = RightPanelStore;
diff --git a/src/web/js/stores/__tests__/TodoStore-test.js b/src/web/js/stores/__tests__/TodoStore-test.js
deleted file mode 100644
index 6da6cd3c..00000000
--- a/src/web/js/stores/__tests__/TodoStore-test.js
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2014-2015, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * TodoStore-test
- */
-
-jest.dontMock('../../constants/TodoConstants');
-jest.dontMock('../TodoStore');
-jest.dontMock('object-assign');
-
-describe('TodoStore', function() {
-
- var TodoConstants = require('../../constants/TodoConstants');
- var AppDispatcher;
- var TodoStore;
- var callback;
-
- // mock actions
- var actionTodoCreate = {
- actionType: TodoConstants.TODO_CREATE,
- text: 'foo'
- };
- var actionTodoDestroy = {
- actionType: TodoConstants.TODO_DESTROY,
- id: 'replace me in test'
- };
-
- beforeEach(function() {
- AppDispatcher = require('../../dispatcher/AppDispatcher');
- TodoStore = require('../TodoStore');
- callback = AppDispatcher.register.mock.calls[0][0];
- });
-
- it('registers a callback with the dispatcher', function() {
- expect(AppDispatcher.register.mock.calls.length).toBe(1);
- });
-
- it('should initialize with no to-do items', function() {
- var all = TodoStore.getAll();
- expect(all).toEqual({});
- });
-
- it('creates a to-do item', function() {
- callback(actionTodoCreate);
- var all = TodoStore.getAll();
- var keys = Object.keys(all);
- expect(keys.length).toBe(1);
- expect(all[keys[0]].text).toEqual('foo');
- });
-
- it('destroys a to-do item', function() {
- callback(actionTodoCreate);
- var all = TodoStore.getAll();
- var keys = Object.keys(all);
- expect(keys.length).toBe(1);
- actionTodoDestroy.id = keys[0];
- callback(actionTodoDestroy);
- expect(all[keys[0]]).toBeUndefined();
- });
-
- it('can determine whether all to-do items are complete', function() {
- var i = 0;
- for (; i < 3; i++) {
- callback(actionTodoCreate);
- }
- expect(Object.keys(TodoStore.getAll()).length).toBe(3);
- expect(TodoStore.areAllComplete()).toBe(false);
-
- var all = TodoStore.getAll();
- for (key in all) {
- callback({
- actionType: TodoConstants.TODO_COMPLETE,
- id: key
- });
- }
- expect(TodoStore.areAllComplete()).toBe(true);
-
- callback({
- actionType: TodoConstants.TODO_UNDO_COMPLETE,
- id: key
- });
- expect(TodoStore.areAllComplete()).toBe(false);
- });
-
-});
bgstack15