From 800d84aa319e9999619f913adb9dd859241414a2 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 26 Feb 2020 23:15:06 +0100 Subject: Removed useless JavaScript code. --- newspipe/web/js/actions/MenuActions.js | 40 -- newspipe/web/js/actions/MiddlePanelActions.js | 132 ------ newspipe/web/js/actions/RightPanelActions.js | 42 -- newspipe/web/js/app.js | 18 - newspipe/web/js/components/MainApp.react.js | 29 -- newspipe/web/js/components/Menu.react.js | 305 -------------- newspipe/web/js/components/MiddlePanel.react.js | 267 ------------ newspipe/web/js/components/Navbar.react.js | 138 ------ newspipe/web/js/components/RightPanel.react.js | 463 --------------------- newspipe/web/js/components/time.react.js | 15 - newspipe/web/js/constants/JarrConstants.js | 13 - newspipe/web/js/dispatcher/JarrDispatcher.js | 16 - .../js/dispatcher/__tests__/AppDispatcher-test.js | 72 ---- newspipe/web/js/stores/MenuStore.js | 135 ------ newspipe/web/js/stores/MiddlePanelStore.js | 126 ------ newspipe/web/js/stores/RightPanelStore.js | 77 ---- newspipe/web/js/stores/__tests__/TodoStore-test.js | 90 ---- 17 files changed, 1978 deletions(-) delete mode 100644 newspipe/web/js/actions/MenuActions.js delete mode 100644 newspipe/web/js/actions/MiddlePanelActions.js delete mode 100644 newspipe/web/js/actions/RightPanelActions.js delete mode 100644 newspipe/web/js/app.js delete mode 100644 newspipe/web/js/components/MainApp.react.js delete mode 100644 newspipe/web/js/components/Menu.react.js delete mode 100644 newspipe/web/js/components/MiddlePanel.react.js delete mode 100644 newspipe/web/js/components/Navbar.react.js delete mode 100644 newspipe/web/js/components/RightPanel.react.js delete mode 100644 newspipe/web/js/components/time.react.js delete mode 100644 newspipe/web/js/constants/JarrConstants.js delete mode 100644 newspipe/web/js/dispatcher/JarrDispatcher.js delete mode 100644 newspipe/web/js/dispatcher/__tests__/AppDispatcher-test.js delete mode 100644 newspipe/web/js/stores/MenuStore.js delete mode 100644 newspipe/web/js/stores/MiddlePanelStore.js delete mode 100644 newspipe/web/js/stores/RightPanelStore.js delete mode 100644 newspipe/web/js/stores/__tests__/TodoStore-test.js diff --git a/newspipe/web/js/actions/MenuActions.js b/newspipe/web/js/actions/MenuActions.js deleted file mode 100644 index 824610d8..00000000 --- a/newspipe/web/js/actions/MenuActions.js +++ /dev/null @@ -1,40 +0,0 @@ -var JarrDispatcher = require('../dispatcher/JarrDispatcher'); -var ActionTypes = require('../constants/JarrConstants'); -var jquery = require('jquery'); - - -var MenuActions = { - // PARENT FILTERS - reload: function(setFilterFunc, id) { - jquery.getJSON('/menu', function(payload) { - JarrDispatcher.dispatch({ - type: ActionTypes.RELOAD_MENU, - feeds: payload.feeds, - categories: payload.categories, - categories_order: payload.categories_order, - is_admin: payload.is_admin, - max_error: payload.max_error, - error_threshold: payload.error_threshold, - crawling_method: payload.crawling_method, - all_unread_count: payload.all_unread_count, - }); - if(setFilterFunc && id) { - setFilterFunc(id); - } - }); - }, - setFilter: function(filter) { - JarrDispatcher.dispatch({ - type: ActionTypes.MENU_FILTER, - filter: filter, - }); - }, - toggleAllFolding: function(all_folded) { - JarrDispatcher.dispatch({ - type: ActionTypes.TOGGLE_MENU_FOLD, - all_folded: all_folded, - }); - }, -}; - -module.exports = MenuActions; diff --git a/newspipe/web/js/actions/MiddlePanelActions.js b/newspipe/web/js/actions/MiddlePanelActions.js deleted file mode 100644 index 700814d4..00000000 --- a/newspipe/web/js/actions/MiddlePanelActions.js +++ /dev/null @@ -1,132 +0,0 @@ -var JarrDispatcher = require('../dispatcher/JarrDispatcher'); -var ActionTypes = require('../constants/JarrConstants'); -var jquery = require('jquery'); -var MiddlePanelStore = require('../stores/MiddlePanelStore'); - -var _last_fetched_with = {}; - -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]; - } - if(filters[key] == null) { - delete filters[key]; - } - }); - if('display_search' in filters) { - delete filters['display_search']; - } - 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(); - }); -} - - -var MiddlePanelActions = { - reload: function() { - reloadAndDispatch({ - type: ActionTypes.RELOAD_MIDDLE_PANEL, - }); - }, - search: function(search) { - reloadAndDispatch({ - type: ActionTypes.RELOAD_MIDDLE_PANEL, - display_search: true, - query: search.query, - search_title: search.title, - search_content: search.content, - }); - }, - search_off: function() { - reloadAndDispatch({ - type: ActionTypes.RELOAD_MIDDLE_PANEL, - display_search: false, - }); - }, - removeParentFilter: function() { - reloadAndDispatch({ - type: ActionTypes.PARENT_FILTER, - filter_type: null, - filter_id: null, - }); - }, - setCategoryFilter: function(category_id) { - reloadAndDispatch({ - type: ActionTypes.PARENT_FILTER, - filter_type: 'category_id', - filter_id: category_id, - }); - }, - setFeedFilter: function(feed_id) { - reloadAndDispatch({ - type: ActionTypes.PARENT_FILTER, - filter_type: 'feed_id', - filter_id: feed_id, - }); - }, - setFilter: function(filter) { - reloadAndDispatch({ - type: ActionTypes.MIDDLE_PANEL_FILTER, - filter: filter, - }); - }, - 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 () { - JarrDispatcher.dispatch({ - type: ActionTypes.CHANGE_ATTR, - attribute: 'read', - value_bool: new_value, - value_num: new_value ? -1 : 1, - articles: [{article_id: article_id, - category_id: category_id, - feed_id: feed_id}], - }); - }, - }); - }, - 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 () { - JarrDispatcher.dispatch({ - type: ActionTypes.CHANGE_ATTR, - attribute: 'liked', - value_bool: new_value, - value_num: new_value ? -1 : 1, - articles: [{article_id: article_id, - category_id: category_id, - feed_id: feed_id}], - }); - }, - }); - }, - markAllAsRead: function() { - var filters = MiddlePanelStore.getRequestFilter(); - jquery.ajax({type: 'PUT', - contentType: 'application/json', - data: JSON.stringify(filters), - url: "/mark_all_as_read", - success: function (payload) { - JarrDispatcher.dispatch({ - type: ActionTypes.MARK_ALL_AS_READ, - articles: payload.articles, - }); - }, - }); - }, -}; - -module.exports = MiddlePanelActions; diff --git a/newspipe/web/js/actions/RightPanelActions.js b/newspipe/web/js/actions/RightPanelActions.js deleted file mode 100644 index 5d78e001..00000000 --- a/newspipe/web/js/actions/RightPanelActions.js +++ /dev/null @@ -1,42 +0,0 @@ -var jquery = require('jquery'); -var JarrDispatcher = require('../dispatcher/JarrDispatcher'); -var ActionTypes = require('../constants/JarrConstants'); -var MenuActions = require('../actions/MenuActions'); - -var RightPanelActions = { - loadArticle: function(article_id, was_read_before, to_parse) { - var suffix = ''; - if(to_parse) { - suffix = '/parse'; - } - jquery.getJSON('/getart/' + article_id + suffix, - function(payload) { - JarrDispatcher.dispatch({ - type: ActionTypes.LOAD_ARTICLE, - article: payload, - was_read_before: was_read_before, - }); - } - ); - }, - _apiReq: function(meth, id, obj_type, data, success_callback) { - var args = {type: meth, contentType: 'application/json', - url: "api/v2.0/" + obj_type + "/" + id} - if(data) {args.data = JSON.stringify(data);} - if(success_callback) {args.success = success_callback;} - jquery.ajax(args); - }, - putObj: function(id, obj_type, fields) { - this._apiReq('PUT', id, obj_type, fields, MenuActions.reload); - }, - delObj: function(id, obj_type, fields) { - this._apiReq('DELETE', id, obj_type, null, MenuActions.reload); - }, - resetErrors: function(feed_id) { - this._apiReq('PUT', feed_id, 'feed', {error_count: 0, last_error: ''}, - MenuActions.reload); - - }, -}; - -module.exports = RightPanelActions; diff --git a/newspipe/web/js/app.js b/newspipe/web/js/app.js deleted file mode 100644 index 7837e6ae..00000000 --- a/newspipe/web/js/app.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) 2014, 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. - */ - -var React = require('react'); -var ReactDOM = require('react-dom'); - -var MainApp = require('./components/MainApp.react'); - -ReactDOM.render( - , - document.getElementById('newspipeapp') -); diff --git a/newspipe/web/js/components/MainApp.react.js b/newspipe/web/js/components/MainApp.react.js deleted file mode 100644 index 32bb663e..00000000 --- a/newspipe/web/js/components/MainApp.react.js +++ /dev/null @@ -1,29 +0,0 @@ -var React = require('react'); -var createReactClass = require('create-react-class'); -var Col = require('react-bootstrap/lib/Col'); -var Grid = require('react-bootstrap/lib/Grid'); -var PropTypes = require('prop-types'); - -var Menu = require('./Menu.react'); -var MiddlePanel = require('./MiddlePanel.react'); -var RightPanel = require('./RightPanel.react'); - - -var MainApp = createReactClass({ - render: function() { - return (
- - - - - - - - -
- ); - }, -}); - -module.exports = MainApp; diff --git a/newspipe/web/js/components/Menu.react.js b/newspipe/web/js/components/Menu.react.js deleted file mode 100644 index 64672240..00000000 --- a/newspipe/web/js/components/Menu.react.js +++ /dev/null @@ -1,305 +0,0 @@ -var React = require('react'); -var createReactClass = require('create-react-class'); -var Col = require('react-bootstrap/lib/Col'); -var Badge = require('react-bootstrap/lib/Badge'); -var Button = require('react-bootstrap/lib/Button'); -var ButtonGroup = require('react-bootstrap/lib/ButtonGroup'); -var Glyphicon = require('react-bootstrap/lib/Glyphicon'); -var PropTypes = require('prop-types'); - -var MenuStore = require('../stores/MenuStore'); -var MenuActions = require('../actions/MenuActions'); -var MiddlePanelActions = require('../actions/MiddlePanelActions'); - -var FeedItem = createReactClass({ - propTypes: {feed_id: PropTypes.number.isRequired, - title: PropTypes.string.isRequired, - unread: PropTypes.number.isRequired, - error_count: PropTypes.number.isRequired, - icon_url: PropTypes.string, - active: PropTypes.bool.isRequired, - }, - render: function() { - var icon = null; - var badge_unread = null; - if(this.props.icon_url){ - icon = (); - } else { - icon = ; - } - if(this.props.unread){ - badge_unread = {this.props.unread}; - } - var classes = "nav-feed"; - if(this.props.active) { - classes += " bg-primary"; - } - if(this.props.error_count >= MenuStore._datas.max_error) { - classes += " bg-danger"; - } else if(this.props.error_count > MenuStore._datas.error_threshold) { - classes += " bg-warning"; - } - var title = {this.props.title}; - return (
  • - {icon}{title}{badge_unread} -
  • - ); - }, - handleClick: function() { - MiddlePanelActions.setFeedFilter(this.props.feed_id); - }, -}); - -var Category = createReactClass({ - propTypes: {category_id: PropTypes.number, - active_type: PropTypes.string, - active_id: PropTypes.number}, - render: function() { - var classes = "nav-cat"; - if((this.props.active_type == 'category_id' - || this.props.category_id == null) - && this.props.active_id == this.props.category_id) { - classes += " bg-primary"; - } - return (
  • - {this.props.children} -
  • - ); - }, - handleClick: function(evnt) { - // hack to avoid selection when clicking on folding icon - if(!evnt.target.classList.contains('glyphicon')) { - if(this.props.category_id != null) { - MiddlePanelActions.setCategoryFilter(this.props.category_id); - } else { - MiddlePanelActions.removeParentFilter(); - } - } - }, -}); - -var CategoryGroup = createReactClass({ - propTypes: {cat_id: PropTypes.number.isRequired, - filter: PropTypes.string.isRequired, - active_type: PropTypes.string, - active_id: PropTypes.number, - name: PropTypes.string.isRequired, - feeds: PropTypes.array.isRequired, - unread: PropTypes.number.isRequired, - folded: PropTypes.bool, - }, - getInitialState: function() { - return {folded: false}; - }, - componentWillReceiveProps: function(nextProps) { - if(nextProps.folded != null) { - this.setState({folded: nextProps.folded}); - } - }, - render: function() { - // hidden the no category if empty - if(!this.props.cat_id && !this.props.feeds.length) { - return
      ; - } - var filter = this.props.filter; - var a_type = this.props.active_type; - var a_id = this.props.active_id; - if(!this.state.folded) { - // filtering according to this.props.filter - var feeds = this.props.feeds.filter(function(feed) { - if (filter == 'unread' && feed.unread <= 0) { - return false; - } else if (filter == 'error' && feed.error_count <= MenuStore._datas.error_threshold) { - return false; - } - return true; - }).sort(function(feed_a, feed_b){ - return feed_b.unread - feed_a.unread; - }).map(function(feed) { - return ( - ); - }); - } else { - var feeds = []; - } - var unread = null; - if(this.props.unread) { - unread = {this.props.unread}; - } - var ctrl = ( - ); - - return (
        - - {ctrl}

        {this.props.name}

        {unread} -
        - {feeds} -
      - ); - }, - toggleFolding: function(evnt) { - this.setState({folded: !this.state.folded}); - evnt.stopPropagation(); - }, -}); - -var MenuFilter = createReactClass({ - propTypes: {feed_in_error: PropTypes.bool, - filter: PropTypes.string.isRequired}, - getInitialState: function() { - return {allFolded: false}; - }, - render: function() { - var error_button = null; - if (this.props.feed_in_error) { - error_button = ( - - ); - } - if(this.state.allFolded) { - var foldBtnTitle = "Unfold all categories"; - var foldBtnGlyph = "option-horizontal"; - } else { - var foldBtnTitle = "Fold all categories"; - var foldBtnGlyph = "option-vertical"; - } - return (
      - - - - {error_button} - - - - - - - -
      - ); - }, - setAllFilter: function() { - MenuActions.setFilter("all"); - }, - setUnreadFilter: function() { - MenuActions.setFilter("unread"); - }, - setErrorFilter: function() { - MenuActions.setFilter("error"); - }, - toggleFold: function() { - this.setState({allFolded: !this.state.allFolded}, function() { - MenuActions.toggleAllFolding(this.state.allFolded); - }.bind(this)); - }, -}); - -var Menu = createReactClass({ - getInitialState: function() { - return {filter: 'unread', categories: {}, feeds: {}, - all_folded: false, active_type: null, active_id: null}; - }, - render: function() { - var feed_in_error = false; - var rmPrntFilt = ( -
        - -

        All

        -
        -
      - ); - var categories = []; - for(var index in this.state.categories_order) { - var cat_id = this.state.categories_order[index]; - var feeds = []; - var unread = 0; - this.state.categories[cat_id].feeds.map(function(feed_id) { - if(this.state.feeds[feed_id].error_count > MenuStore._datas.error_threshold) { - feed_in_error = true; - } - unread += this.state.feeds[feed_id].unread; - feeds.push(this.state.feeds[feed_id]); - }.bind(this)); - categories.push(); - } - - return ( - - {rmPrntFilt} - {categories} - - ); - }, - componentDidMount: function() { - var setFilterFunc = null; - var id = null; - if(window.location.search.substring(1)) { - var args = window.location.search.substring(1).split('&'); - args.map(function(arg) { - if (arg.split('=')[0] == 'at' && arg.split('=')[1] == 'c') { - setFilterFunc = MiddlePanelActions.setCategoryFilter; - } else if (arg.split('=')[0] == 'at' && arg.split('=')[1] == 'f') { - setFilterFunc = MiddlePanelActions.setFeedFilter; - - } else if (arg.split('=')[0] == 'ai') { - id = parseInt(arg.split('=')[1]); - } - }); - } - MenuActions.reload(setFilterFunc, id); - MenuStore.addChangeListener(this._onChange); - }, - componentWillUnmount: function() { - MenuStore.removeChangeListener(this._onChange); - }, - _onChange: function() { - var datas = MenuStore.getAll(); - this.setState({filter: datas.filter, - feeds: datas.feeds, - categories: datas.categories, - categories_order: datas.categories_order, - active_type: datas.active_type, - active_id: datas.active_id, - all_folded: datas.all_folded}); - }, -}); - -module.exports = Menu; diff --git a/newspipe/web/js/components/MiddlePanel.react.js b/newspipe/web/js/components/MiddlePanel.react.js deleted file mode 100644 index fc7c763a..00000000 --- a/newspipe/web/js/components/MiddlePanel.react.js +++ /dev/null @@ -1,267 +0,0 @@ -var React = require('react'); -var createReactClass = require('create-react-class'); - -var Row = require('react-bootstrap/lib/Row'); -var Button = require('react-bootstrap/lib/Button'); -var ButtonGroup = require('react-bootstrap/lib/ButtonGroup'); -var Glyphicon = require('react-bootstrap/lib/Glyphicon'); -var PropTypes = require('prop-types'); - -var MiddlePanelStore = require('../stores/MiddlePanelStore'); -var MiddlePanelActions = require('../actions/MiddlePanelActions'); -var RightPanelActions = require('../actions/RightPanelActions'); - -var JarrTime = require('./time.react'); - -var TableLine = createReactClass({ - propTypes: {article_id: PropTypes.number.isRequired, - feed_title: PropTypes.string.isRequired, - icon_url: PropTypes.string, - title: PropTypes.string.isRequired, - rel_date: PropTypes.string.isRequired, - date: PropTypes.string.isRequired, - read: PropTypes.bool.isRequired, - selected: PropTypes.bool.isRequired, - liked: PropTypes.bool.isRequired, - }, - getInitialState: function() { - return {read: this.props.read, liked: this.props.liked, - selected: false}; - }, - render: function() { - var liked = this.state.liked ? 'l' : ''; - var icon = null; - if(this.props.icon_url){ - icon = (); - } else { - icon = ; - } - var title = ( - {icon} {this.props.feed_title} - ); - var read = (); - var liked = (); - icon = ; - var clsses = "list-group-item"; - if(this.props.selected) { - clsses += " active"; - } - return (
      -
      {title}
      - -
      {read} {liked} {this.props.title}
      -
      - ); - }, - openRedirectLink: function(evnt) { - if(!this.state.read) { - this.toogleRead(evnt); - } - }, - toogleRead: function(evnt) { - this.setState({read: !this.state.read}, function() { - MiddlePanelActions.changeRead(this.props.category_id, - this.props.feed_id, this.props.article_id, this.state.read); - }.bind(this)); - evnt.stopPropagation(); - }, - toogleLike: function(evnt) { - this.setState({liked: !this.state.liked}, function() { - MiddlePanelActions.changeLike(this.props.category_id, - this.props.feed_id, this.props.article_id, this.state.liked); - }.bind(this)); - evnt.stopPropagation(); - }, - loadArticle: function() { - this.setState({selected: true, read: true}, function() { - RightPanelActions.loadArticle( - this.props.article_id, this.props.read); - }.bind(this)); - }, - stopPropagation: function(evnt) { - evnt.stopPropagation(); - }, -}); - -var MiddlePanelSearchRow = createReactClass({ - getInitialState: function() { - return {query: MiddlePanelStore._datas.query, - search_title: MiddlePanelStore._datas.search_title, - search_content: MiddlePanelStore._datas.search_content, - }; - }, - render: function() { - return ( -
      -
      - - Title - - - - Content - - - -
      -
      -
      - ); - }, - setQuery: function(evnt) { - this.setState({query: evnt.target.value}); - }, - toogleSTitle: function() { - this.setState({search_title: !this.state.search_title}, - this.launchSearch); - }, - toogleSContent: function() { - this.setState({search_content: !this.state.search_content}, - this.launchSearch); - }, - launchSearch: function(evnt) { - if(this.state.query && (this.state.search_title - || this.state.search_content)) { - MiddlePanelActions.search({query: this.state.query, - title: this.state.search_title, - content: this.state.search_content}); - } - if(evnt) { - evnt.preventDefault(); - } - }, -}); - -var MiddlePanelFilter = createReactClass({ - getInitialState: function() { - return {filter: MiddlePanelStore._datas.filter, - display_search: MiddlePanelStore._datas.display_search}; - }, - render: function() { - var search_row = null; - if(this.state.display_search) { - search_row = - } - return (
      - - - - - - - - - - - - - - {search_row} -
      - ); - }, - setAllFilter: function() { - this.setState({filter: 'all'}, function() { - MiddlePanelActions.setFilter('all'); - }.bind(this)); - }, - setUnreadFilter: function() { - this.setState({filter: 'unread'}, function() { - MiddlePanelActions.setFilter('unread'); - }.bind(this)); - }, - setLikedFilter: function() { - this.setState({filter: 'liked'}, function() { - MiddlePanelActions.setFilter('liked'); - }.bind(this)); - }, - toogleSearch: function() { - this.setState({display_search: !this.state.display_search}, - function() { - if(!this.state.display_search) { - MiddlePanelActions.search_off(); - } - }.bind(this) - ); - }, -}); - -var MiddlePanel = createReactClass({ - getInitialState: function() { - return {filter: MiddlePanelStore._datas.filter, articles: []}; - }, - render: function() { - return ( -
      - {this.state.articles.map(function(article){ - var key = "a" + article.article_id; - if(article.read) {key+="r";} - if(article.liked) {key+="l";} - if(article.selected) {key+="s";} - return ();})} -
      -
      - ); - }, - componentDidMount: function() { - MiddlePanelActions.reload(); - MiddlePanelStore.addChangeListener(this._onChange); - }, - componentWillUnmount: function() { - MiddlePanelStore.removeChangeListener(this._onChange); - }, - _onChange: function() { - this.setState({filter: MiddlePanelStore._datas.filter, - articles: MiddlePanelStore.getArticles()}); - }, -}); - -module.exports = {MiddlePanel: MiddlePanel, - MiddlePanelFilter: MiddlePanelFilter}; diff --git a/newspipe/web/js/components/Navbar.react.js b/newspipe/web/js/components/Navbar.react.js deleted file mode 100644 index 83f3c72c..00000000 --- a/newspipe/web/js/components/Navbar.react.js +++ /dev/null @@ -1,138 +0,0 @@ -var React = require('react'); -var createReactClass = require('create-react-class'); -var Glyphicon = require('react-bootstrap/lib/Glyphicon'); -var Nav = require('react-bootstrap/lib/Nav'); -var NavItem = require('react-bootstrap/lib/NavItem'); -var Navbar = require('react-bootstrap/lib/Navbar'); -var NavDropdown = require('react-bootstrap/lib/NavDropdown'); -var MenuItem = require('react-bootstrap/lib/MenuItem'); -var Modal = require('react-bootstrap/lib/Modal'); -var Button = require('react-bootstrap/lib/Button'); -var Input = require('react-bootstrap/lib/Input'); - -var MenuStore = require('../stores/MenuStore'); - -JarrNavBar = createReactClass({ - getInitialState: function() { - return {is_admin: MenuStore._datas.is_admin, - crawling_method: MenuStore._datas.crawling_method, - showModal: false, modalType: null}; - }, - buttonFetch: function() { - if(this.state.is_admin && this.state.crawling_method != 'http') { - return ( - Fetch - ); - } - }, - sectionAdmin: function() { - if(this.state.is_admin) { - return ( - Dashboard - ); - } - }, - getModal: function() { - var heading = null; - var action = null; - var body = null; - if(this.state.modalType == 'addFeed') { - heading = 'Add a new feed'; - action = '/feed/bookmarklet'; - placeholder = "Site or feed url"; - body = ; - } else { - heading = 'Add a new category'; - action = '/category/create'; - body = ; - } - return ( -
      - - {heading} - - - {body} - - - - -
      -
      ); - }, - close: function() { - this.setState({showModal: false, modalType: null}); - }, - openAddFeed: function() { - this.setState({showModal: true, modalType: 'addFeed'}); - }, - openAddCategory: function() { - this.setState({showModal: true, modalType: 'addCategory'}); - }, - render: function() { - return ( - {this.getModal()} - - - Newspipe - - - - - - - - ); - }, - componentDidMount: function() { - MenuStore.addChangeListener(this._onChange); - }, - componentWillUnmount: function() { - MenuStore.removeChangeListener(this._onChange); - }, - _onChange: function() { - var datas = MenuStore.getAll(); - this.setState({is_admin: datas.is_admin, - crawling_method: datas.crawling_method}); - }, -}); - -module.exports = JarrNavBar; diff --git a/newspipe/web/js/components/RightPanel.react.js b/newspipe/web/js/components/RightPanel.react.js deleted file mode 100644 index 6384cdfe..00000000 --- a/newspipe/web/js/components/RightPanel.react.js +++ /dev/null @@ -1,463 +0,0 @@ -var React = require('react'); -var createReactClass = require('create-react-class'); -var Col = require('react-bootstrap/lib/Col'); -var Glyphicon = require('react-bootstrap/lib/Glyphicon'); -var Button = require('react-bootstrap/lib/Button'); -var ButtonGroup = require('react-bootstrap/lib/ButtonGroup'); -var Modal = require('react-bootstrap/lib/Modal'); -var PropTypes = require('prop-types'); - -var RightPanelActions = require('../actions/RightPanelActions'); -var RightPanelStore = require('../stores/RightPanelStore'); -var MenuStore = require('../stores/MenuStore'); -var JarrTime = require('./time.react'); - -var PanelMixin = { - propTypes: {obj: PropTypes.object.isRequired}, - getInitialState: function() { - return {edit_mode: false, obj: this.props.obj, showModal: false}; - }, - getHeader: function() { - var icon = null; - if(this.props.obj.icon_url){ - icon = (); - } - var btn_grp = null; - if(this.isEditable() || this.isRemovable()) { - var edit_button = null; - if(this.isEditable()) { - edit_button = (); - } - var rem_button = null; - if(this.isRemovable()) { - rem_button = (); - } - btn_grp = ( - {edit_button} - {rem_button} - ); - } - return (
      - - - Are you sure ? - - - - - - -

      {icon}{this.getTitle()}

      - {btn_grp} -
      ); - }, - getKey: function(prefix, suffix) { - return ((this.state.edit_mode?'edit':'fix') + prefix - + '-' + this.props.obj.id + '-' + suffix); - }, - getCore: function() { - var items = []; - var key; - if(!this.state.edit_mode) { - this.fields.filter(function(field) { - return field.type != 'ignore'; - }).map(function(field) { - key = this.getKey('dt', field.key); - items.push(
      {field.title}
      ); - key = this.getKey('dd', field.key); - if(field.type == 'string') { - items.push(
      {this.props.obj[field.key]}
      ); - } else if(field.type == 'bool') { - if(this.props.obj[field.key]) { - items.push(
      ); - } else { - items.push(
      ); - } - } else if (field.type == 'list') { - items.push(
      {this.props.obj[field.key].reduce(function(previousTag, currentTag) { - return currentTag.concat(", ", previousTag) - }, "")}
      ) - } else if (field.type == 'link') { - items.push(
      - - {this.props.obj[field.key]} - -
      ); - } - }.bind(this)); - } else { - this.fields.filter(function(field) { - return field.type != 'ignore'; - }).map(function(field) { - key = this.getKey('dd', field.key); - items.push(
      {field.title}
      ); - key = this.getKey('dt', field.key); - var input = null; - if(field.type == 'string' || field.type == 'link') { - input = (); - } else if (field.type == 'bool') { - input = (); - } - items.push(
      {input}
      ); - }.bind(this)); - } - return (
      {items}
      ); - }, - getSubmit: function() { - return (
      - -
      ); - }, - render: function() { - return (
      - {this.getHeader()} - {this.getBody()} -
      - ); - }, - onClickEdit: function() { - this.setState({edit_mode: !this.state.edit_mode}); - }, - onClickRemove: function() { - this.setState({showModal: true}); - }, - closeModal: function() { - this.setState({showModal: false}); - }, - confirmDelete: function() { - this.setState({showModal: false}, function() { - RightPanelActions.delObj(this.props.obj.id, this.obj_type); - }.bind(this)); - }, - saveField: function(evnt) { - var obj = this.state.obj; - for(var i in this.fields) { - if(evnt.target.name == this.fields[i].key) { - if(this.fields[i].type == 'bool') { - obj[evnt.target.name] = evnt.target.checked; - } else { - obj[evnt.target.name] = evnt.target.value; - } - break; - } - } - this.setState({obj: obj}); - }, - saveObj: function() { - var to_push = {}; - this.fields.map(function(field) { - to_push[field.key] = this.state.obj[field.key]; - }.bind(this)); - this.setState({edit_mode: false}, function() { - RightPanelActions.putObj(this.props.obj.id, this.obj_type, to_push); - }.bind(this)); - }, -}; - -var Article = createReactClass({ - mixins: [PanelMixin], - isEditable: function() {return false;}, - isRemovable: function() {return true;}, - fields: [{'title': 'Date', 'type': 'string', 'key': 'date'}, - {'title': 'Original link', 'type': 'link', 'key': 'link'}, - {'title': 'Tags', 'type': 'list', 'key': 'tags'} - ], - obj_type: 'article', - getTitle: function() {return this.props.obj.title;}, - getBody: function() { - return (
      - {this.getCore()} -
      -
      ); - } -}); - -var Feed = createReactClass({ - mixins: [PanelMixin], - isEditable: function() {return true;}, - isRemovable: function() {return true;}, - obj_type: 'feed', - fields: [{'title': 'Feed title', 'type': 'string', 'key': 'title'}, - {'title': 'Description', 'type': 'string', 'key': 'description'}, - {'title': 'Feed link', 'type': 'link', 'key': 'link'}, - {'title': 'Site link', 'type': 'link', 'key': 'site_link'}, - {'title': 'Enabled', 'type': 'bool', 'key': 'enabled'}, - {'title': 'Private', 'type': 'bool', 'key': 'private'}, - {'title': 'Filters', 'type': 'ignore', 'key': 'filters'}, - {'title': 'Category', 'type': 'ignore', 'key': 'category_id'}, - ], - getTitle: function() {return this.props.obj.title;}, - getFilterRow: function(i, filter) { - return (
      - - - - - - - -
      ); - }, - getFilterRows: function() { - var rows = []; - if(this.state.edit_mode) { - for(var i in this.state.obj.filters) { - rows.push(this.getFilterRow(i, this.state.obj.filters[i])); - } - return (
      -
      Filters
      -
      - -
      - {rows} -
      ); - } - rows = []; - rows.push(
      Filters
      ); - for(var i in this.state.obj.filters) { - rows.push(
      - When {this.state.obj.filters[i]['action on']} - on "{this.state.obj.filters[i].pattern}" - ({this.state.obj.filters[i].type}) - "=" {this.state.obj.filters[i].action} -
      ); - } - return
      {rows}
      ; - }, - getCategorySelect: function() { - var content = null; - if(this.state.edit_mode) { - var categ_options = []; - for(var index in MenuStore._datas.categories_order) { - var cat_id = MenuStore._datas.categories_order[index]; - categ_options.push( - ); - } - content = (); - } else { - content = MenuStore._datas.categories[this.props.obj.category_id].name; - } - return (
      -
      Category
      {content}
      -
      ); - }, - getErrorFields: function() { - if(this.props.obj.error_count < MenuStore._datas.error_threshold) { - return; - } - if(this.props.obj.error_count < MenuStore._datas.max_error) { - return (
      -
      State
      -
      The download of this feed has encountered some problems. However its error counter will be reinitialized at the next successful retrieving.
      -
      Last error
      -
      {this.props.obj.last_error}
      -
      ); - } - return (
      -
      State
      -
      That feed has encountered too much consecutive errors and won't be retrieved anymore.
      - -
      Last error
      -
      {this.props.obj.last_error}
      -
      - -
      -
      ); - - }, - resetErrors: function() { - var obj = this.state.obj; - obj.error_count = 0; - this.setState({obj: obj}, function() { - RightPanelActions.resetErrors(this.props.obj.id); - }.bind(this)); - }, - getBody: function() { - return (
      -
      -
      Created on
      -
      -
      -
      Last fetched
      -
      -
      -
      - {this.getErrorFields()} - {this.getCategorySelect()} - {this.getCore()} - {this.getFilterRows()} - {this.state.edit_mode?this.getSubmit():null} -
      - ); - }, - addFilterRow: function() { - var obj = this.state.obj; - obj.filters.push({action: "mark as read", 'action on': "match", - type: "simple match", pattern: ""}); - this.setState({obj: obj}); - }, - removeFilterRow: function(evnt) { - var obj = this.state.obj; - delete obj.filters[evnt.target.getAttribute('data-index')]; - this.setState({obj: obj}); - }, - saveFilterChange: function(evnt) { - var index = evnt.target.getAttribute('data-index'); - var obj = this.state.obj; - obj.filters[index][evnt.target.name] = evnt.target.value; - this.setState({obj: obj}); - }, -}); - -var Category = createReactClass({ - mixins: [PanelMixin], - isEditable: function() { - if(this.props.obj.id != 0) {return true;} - else {return false;} - }, - isRemovable: function() {return this.isEditable();}, - obj_type: 'category', - fields: [{'title': 'Category name', 'type': 'string', 'key': 'name'}], - getTitle: function() {return this.props.obj.name;}, - getBody: function() { - return (
      - {this.getCore()} - {this.state.edit_mode?this.getSubmit():null} -
      ); - }, -}); - -var RightPanel = createReactClass({ - getInitialState: function() { - return {category: null, feed: null, article: null, current: null}; - }, - getCategoryCrum: function() { - return (
    • - {this.state.category.name} -
    • ); - }, - getFeedCrum: function() { - return (
    • - {this.state.feed.title} -
    • ); - }, - getArticleCrum: function() { - return
    • {this.state.article.title}
    • ; - }, - render: function() { - window.scrollTo(0, 0); - var brd_category = null; - var brd_feed = null; - var brd_article = null; - var breadcrum = null; - if(this.state.category) { - brd_category = (
    • - - {this.state.category.name} - -
    • ); - } - if(this.state.feed) { - brd_feed = (
    • - - {this.state.feed.title} - -
    • ); - } - if(this.state.article) { - brd_article =
    • {this.state.article.title}
    • ; - } - if(brd_category || brd_feed || brd_article) { - breadcrum = (
        - {brd_category} - {brd_feed} - {brd_article} -
      ); - } - if(this.state.current == 'article') { - var cntnt = (
      ); - } else if(this.state.current == 'feed') { - var cntnt = (); - } else if(this.state.current == 'category') { - var cntnt = (); - } - - return ( - {breadcrum} - {cntnt} - - ); - }, - selectCategory: function() { - this.setState({current: 'category'}); - }, - selectFeed: function() { - this.setState({current: 'feed'}); - }, - selectArticle: function() { - this.setState({current: 'article'}); - }, - componentDidMount: function() { - RightPanelStore.addChangeListener(this._onChange); - }, - componentWillUnmount: function() { - RightPanelStore.removeChangeListener(this._onChange); - }, - _onChange: function() { - this.setState(RightPanelStore.getAll()); - }, -}); - -module.exports = RightPanel; diff --git a/newspipe/web/js/components/time.react.js b/newspipe/web/js/components/time.react.js deleted file mode 100644 index 07e1fbdf..00000000 --- a/newspipe/web/js/components/time.react.js +++ /dev/null @@ -1,15 +0,0 @@ -var React = require('react'); -var createReactClass = require('create-react-class'); -var PropTypes = require('prop-types'); - -var JarrTime = createReactClass({ - propTypes: {stamp: PropTypes.string.isRequired, - text: PropTypes.string.isRequired}, - render: function() { - return (); - }, -}); - -module.exports = JarrTime; diff --git a/newspipe/web/js/constants/JarrConstants.js b/newspipe/web/js/constants/JarrConstants.js deleted file mode 100644 index 78e8bf04..00000000 --- a/newspipe/web/js/constants/JarrConstants.js +++ /dev/null @@ -1,13 +0,0 @@ -var keyMirror = require('keymirror'); - -module.exports = keyMirror({ - TOGGLE_MENU_FOLD: null, - RELOAD_MENU: null, - PARENT_FILTER: null, // set a feed or a category as filter in menu - MENU_FILTER: null, // change displayed feed in the menu - CHANGE_ATTR: null, // edit an attr on an article (like / read) - RELOAD_MIDDLE_PANEL: null, - MIDDLE_PANEL_FILTER: null, // set a filter (read/like/all) - LOAD_ARTICLE: null, // load a single article in right panel - MARK_ALL_AS_READ: null, -}); diff --git a/newspipe/web/js/dispatcher/JarrDispatcher.js b/newspipe/web/js/dispatcher/JarrDispatcher.js deleted file mode 100644 index 56da186f..00000000 --- a/newspipe/web/js/dispatcher/JarrDispatcher.js +++ /dev/null @@ -1,16 +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. - * - * AppDispatcher - * - * A singleton that operates as the central hub for application updates. - */ - -var Dispatcher = require('flux').Dispatcher; - -module.exports = new Dispatcher(); diff --git a/newspipe/web/js/dispatcher/__tests__/AppDispatcher-test.js b/newspipe/web/js/dispatcher/__tests__/AppDispatcher-test.js deleted file mode 100644 index d3a35fc5..00000000 --- a/newspipe/web/js/dispatcher/__tests__/AppDispatcher-test.js +++ /dev/null @@ -1,72 +0,0 @@ -"use strict"; - -jest.autoMockOff(); - -describe('AppDispatcher', function() { - var AppDispatcher; - - beforeEach(function() { - AppDispatcher = require('../AppDispatcher.js'); - }); - - it('sends actions to subscribers', function() { - var listener = jest.genMockFunction(); - AppDispatcher.register(listener); - - var payload = {}; - AppDispatcher.dispatch(payload); - expect(listener.mock.calls.length).toBe(1); - expect(listener.mock.calls[0][0]).toBe(payload); - }); - - it('waits with chained dependencies properly', function() { - var payload = {}; - - var listener1Done = false; - var listener1 = function(pl) { - AppDispatcher.waitFor([index2, index4]); - // Second, third, and fourth listeners should have now been called - expect(listener2Done).toBe(true); - expect(listener3Done).toBe(true); - expect(listener4Done).toBe(true); - listener1Done = true; - }; - var index1 = AppDispatcher.register(listener1); - - var listener2Done = false; - var listener2 = function(pl) { - AppDispatcher.waitFor([index3]); - expect(listener3Done).toBe(true); - listener2Done = true; - }; - var index2 = AppDispatcher.register(listener2); - - var listener3Done = false; - var listener3 = function(pl) { - listener3Done = true; - }; - var index3 = AppDispatcher.register(listener3); - - var listener4Done = false; - var listener4 = function(pl) { - AppDispatcher.waitFor([index3]); - expect(listener3Done).toBe(true); - listener4Done = true; - }; - var index4 = AppDispatcher.register(listener4); - - runs(function() { - AppDispatcher.dispatch(payload); - }); - - waitsFor(function() { - return listener1Done; - }, "Not all subscribers were properly called", 500); - - runs(function() { - expect(listener1Done).toBe(true); - expect(listener2Done).toBe(true); - expect(listener3Done).toBe(true); - }); - }); -}); diff --git a/newspipe/web/js/stores/MenuStore.js b/newspipe/web/js/stores/MenuStore.js deleted file mode 100644 index 770bc501..00000000 --- a/newspipe/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/newspipe/web/js/stores/MiddlePanelStore.js b/newspipe/web/js/stores/MiddlePanelStore.js deleted file mode 100644 index c554f929..00000000 --- a/newspipe/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/newspipe/web/js/stores/RightPanelStore.js b/newspipe/web/js/stores/RightPanelStore.js deleted file mode 100644 index 6c268dfd..00000000 --- a/newspipe/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/newspipe/web/js/stores/__tests__/TodoStore-test.js b/newspipe/web/js/stores/__tests__/TodoStore-test.js deleted file mode 100644 index 6da6cd3c..00000000 --- a/newspipe/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); - }); - -}); -- cgit