From 7c5d605184cb1f9fe95b039da01e2b2b440fd0f6 Mon Sep 17 00:00:00 2001 From: Anton Korneyev Date: Sun, 2 Jul 2017 18:31:46 +0400 Subject: [PATCH 1/3] articles now an object, not array --- src/components/ArticleList.js | 11 ++++++----- src/components/Filters/Select.js | 12 +++++++----- src/reducer/articles.js | 13 +++++++++++-- src/selectors/index.js | 15 +++++++++++---- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/components/ArticleList.js b/src/components/ArticleList.js index 24568b6..5bfb096 100644 --- a/src/components/ArticleList.js +++ b/src/components/ArticleList.js @@ -8,7 +8,7 @@ import {filtratedArticlesSelector} from '../selectors' class ArticleList extends Component { static propTypes = { //from connect - articles: PropTypes.array.isRequired, + articles: PropTypes.object.isRequired, //from accordion openItemId: PropTypes.string, toggleOpenItem: PropTypes.func.isRequired @@ -17,11 +17,12 @@ class ArticleList extends Component { render() { console.log('---', 'update article list') const { articles, openItemId, toggleOpenItem } = this.props - const articleElements = articles.map(article =>
  • + const articleElements = Object.keys(articles).map(key => +
  • ) diff --git a/src/components/Filters/Select.js b/src/components/Filters/Select.js index fdd66aa..1a76d13 100644 --- a/src/components/Filters/Select.js +++ b/src/components/Filters/Select.js @@ -7,17 +7,19 @@ import 'react-select/dist/react-select.css' class SelectFilter extends Component { static propTypes = { - articles: PropTypes.array.isRequired + articles: PropTypes.object.isRequired }; handleChange = selected => this.props.changeSelection(selected.map(option => option.value)) render() { const { articles, selected } = this.props - const options = articles.map(article => ({ - label: article.title, - value: article.id - })) + const options = Object.keys(articles).map(key => { + return { + label: articles[key].title, + value: key + } + }) return { const published = Date.parse(articles[key].date) - if ((!selected.length || selected.includes(articles[key])) && + if ((!selected.length || selected.includes(key)) && (!from || !to || (published > from && published < to))) { filtered[key] = articles[key] } }) - return filtered })