diff --git a/src/AC/index.js b/src/AC/index.js index dda2dd6..ee1f241 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, ADD_COMMENT, CHANGE_DATE_RANGE, CHANGE_SELECTION} from '../constants' export function increment() { return { @@ -26,3 +26,10 @@ export function changeSelection(selected) { payload: { selected } } } + +export function addComment(text) { + return { + type: ADD_COMMENT, + payload: { text } + } +} diff --git a/src/components/article-list/index.js b/src/components/article-list/index.js index f2cebc8..c5b5fdf 100644 --- a/src/components/article-list/index.js +++ b/src/components/article-list/index.js @@ -20,13 +20,13 @@ export class ArticleList extends Component { render() { const { articles, openItemId, toggleItem } = this.props - console.log('---', 'rendering ArticlList') - const articleElements = articles.map(article => -
  • + console.log('---', 'rendering ArticlList', articles) + const articleElements = articles.map(id => +
  • ) @@ -43,4 +43,4 @@ export default connect(state => { return { articles: filtratedArticles(state) } -})(accordion(ArticleList)) \ No newline at end of file +})(accordion(ArticleList)) diff --git a/src/components/article/index.js b/src/components/article/index.js index 96261d8..6ec65e8 100644 --- a/src/components/article/index.js +++ b/src/components/article/index.js @@ -4,6 +4,7 @@ import CSSTransition from 'react-addons-css-transition-group' import { connect } from 'react-redux' import CommentList from '../comment-list' import { deleteArticle } from '../../AC' +import { createArticleSelector } from '../../selectors' import './style.css' class Article extends PureComponent { @@ -48,6 +49,10 @@ class Article extends PureComponent { ) } + handleAdd = () => { + + } + handleDelete = () => { const { deleteArticle, article } = this.props deleteArticle(article.id) @@ -73,4 +78,13 @@ Article.propTypes = { onButtonClick: PropTypes.func } -export default connect(null, { deleteArticle })(Article) \ No newline at end of file +const createMapStateToProps = () => { + const articleSelector = createArticleSelector() + + return (state, ownProps) => ({ + article: articleSelector(state, ownProps) + }) +} + + +export default connect(createMapStateToProps, { deleteArticle })(Article) diff --git a/src/components/comment-list/index.js b/src/components/comment-list/index.js index 91c4f08..f43a08c 100644 --- a/src/components/comment-list/index.js +++ b/src/components/comment-list/index.js @@ -1,12 +1,15 @@ -import React, {Component} from 'react' +import React, {Component, Fragment} from 'react' import PropTypes from 'prop-types' import CSSTransition from 'react-addons-css-transition-group' import Comment from '../comment' import toggleOpen from '../../decorators/toggleOpen' +import { addComment } from '../../AC' +import { connect } from 'react-redux' import './style.css' class CommentList extends Component { static defaultProps = { + comment: '', comments: [] } @@ -17,6 +20,19 @@ class CommentList extends Component { toggleOpen: PropTypes.func } + handleAdd = () => { + const { comment } = this.state + const { addComment } = this.props + console.log('add', comment) + addComment(comment) + this.setState({comment: ''}) + } + + handleChange = (event) => { + console.log('change', event.target.value) + this.setState({comment: event.target.value}) + } + render() { const {isOpen, toggleOpen} = this.props const text = isOpen ? 'hide comments' : 'show comments' @@ -30,6 +46,14 @@ class CommentList extends Component { > {this.getBody()} + + { isOpen && +