From 965c24c4d30ddbe3ab4f08fe49d635eefcbf8e71 Mon Sep 17 00:00:00 2001 From: Denis1990 Date: Fri, 2 Feb 2018 23:48:35 +0300 Subject: [PATCH 1/2] Refactor articles --- src/components/Article/index.js | 11 ++++++++++- src/components/ArticleList.js | 8 ++++---- src/components/Comment.js | 1 + src/components/Filters/Select.js | 8 ++++---- src/reducer/articles.js | 15 +++++++++++++-- src/selectors/index.js | 11 ++++++++--- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/components/Article/index.js b/src/components/Article/index.js index a3e834e..74657dc 100644 --- a/src/components/Article/index.js +++ b/src/components/Article/index.js @@ -5,6 +5,7 @@ import CSSTransition from 'react-addons-css-transition-group' import {connect} from 'react-redux' import CommentList from '../CommentList' import {deleteArticle} from '../../AC' +import {createArticleSelector} from '../../selectors' import './style.css' class Article extends PureComponent { @@ -85,5 +86,13 @@ class Article extends PureComponent { } +const createMapStateToProps = () => { + const articleSelector = createArticleSelector() + return (state, ownProps) => { + return { + article: articleSelector(state, ownProps) + } + } +} -export default connect(null, { deleteArticle })(Article) \ No newline at end of file +export default connect(createMapStateToProps, { deleteArticle })(Article) \ No newline at end of file diff --git a/src/components/ArticleList.js b/src/components/ArticleList.js index bc1c261..4ec975e 100644 --- a/src/components/ArticleList.js +++ b/src/components/ArticleList.js @@ -10,10 +10,10 @@ class ArticleList extends Accordion { console.log('---', 'rerendering article list') const {articles} = this.props if (!articles.length) return

No Articles

- const articleElements = articles.map((article) =>
  • -
  • +
  • ) return ( diff --git a/src/components/Comment.js b/src/components/Comment.js index 4b123ce..b3f9d4c 100644 --- a/src/components/Comment.js +++ b/src/components/Comment.js @@ -22,6 +22,7 @@ Comment.propTypes = { const createMapStateToProps = () => { const commentSelector = createCommentSelector() + console.log('state Comment--', state) return (state, ownProps) => { return { comment: commentSelector(state, ownProps) diff --git a/src/components/Filters/Select.js b/src/components/Filters/Select.js index 1a91857..969f9bd 100644 --- a/src/components/Filters/Select.js +++ b/src/components/Filters/Select.js @@ -8,16 +8,16 @@ 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(i => ({ + label: articles[i].title, + value: articles[i].id })) return