diff --git a/src/AC/index.js b/src/AC/index.js index dda2dd6..cc26bd0 100644 --- a/src/AC/index.js +++ b/src/AC/index.js @@ -1,4 +1,4 @@ -import {INCREMENT, DELETE_ARTICLE, CHANGE_DATE_RANGE, CHANGE_SELECTION} from '../constants' +import { INCREMENT, DELETE_ARTICLE, CHANGE_DATE_RANGE, CHANGE_SELECTION, ADD_NEW_COMMENT, ADD_NEW_ID_COMMENT_TO_ARCTICLE } from '../constants' export function increment() { return { @@ -26,3 +26,19 @@ export function changeSelection(selected) { payload: { selected } } } + + +export function addNewComment(id, comment) { + return { + type: ADD_NEW_COMMENT, + payload: { id, comment } + } + +} + +export function addIdNewCommentToArticle(idarcticle) { + return { + type: ADD_NEW_ID_COMMENT_TO_ARCTICLE, + payload: { idarcticle } + } +} \ No newline at end of file diff --git a/src/components/Article/index.js b/src/components/Article/index.js index a3e834e..463ae9e 100644 --- a/src/components/Article/index.js +++ b/src/components/Article/index.js @@ -7,16 +7,18 @@ import CommentList from '../CommentList' import {deleteArticle} from '../../AC' import './style.css' +import {createArticleSelector} from '../../selectors' + class Article extends PureComponent { - static propTypes = { - article: PropTypes.shape({ - title: PropTypes.string.isRequired, - text: PropTypes.string, - comments: PropTypes.array - }).isRequired, - isOpen: PropTypes.bool, - toggleOpen: PropTypes.func - } + // static propTypes = { + // article: PropTypes.shape({ + // title: PropTypes.string.isRequired, + // text: PropTypes.string, + // comments: PropTypes.array + // }).isRequired, + // isOpen: PropTypes.bool, + // toggleOpen: PropTypes.func + // } constructor(props) { super(props) @@ -33,7 +35,7 @@ class Article extends PureComponent { const body = isOpen && (
{article.text}
- +
) return ( @@ -84,6 +86,28 @@ class Article extends PureComponent { } } +const createMapStateToProps = (state, ownProps) =>{ + + const articleSelector = createArticleSelector() + + return ( state, ownProps ) => { + return { + article: articleSelector(state , ownProps) + } + } + + +} + +// const createMapStateToProps = () => { +// const commentSelector = createCommentSelector() +// return (state, ownProps) => { +// return { +// comment: commentSelector(state, ownProps) +// } +// } +// } -export default connect(null, { deleteArticle })(Article) \ No newline at end of file +// export default connect(createMapStateToProps)(Article) +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..a3cb8b1 100644 --- a/src/components/ArticleList.js +++ b/src/components/ArticleList.js @@ -7,14 +7,23 @@ import {filtratedArticlesSelector} from '../selectors' class ArticleList extends Accordion { render() { - console.log('---', 'rerendering article list') + + + + + console.log('---', 'rerendering article list' ) const {articles} = this.props + console.log(articles) if (!articles.length) return

No Articles

- const articleElements = articles.map((article) =>
  • -
  • + +
    +
  • ) return (