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 &&
+
+
+
+ }
)
}
@@ -50,6 +74,7 @@ class CommentList extends Component {
}
getComments() {
+ console.log('comments', this.props.comments)
return (
{
@@ -63,5 +88,13 @@ class CommentList extends Component {
}
}
+const createMapStateToProps = (state, ownProps) => {
+ console.log('---', 'comnent list connect')
+ console.log('---', 'ownProps', ownProps)
+ return {
+ comments: ownProps.comments
+ }
+}
-export default toggleOpen(CommentList)
\ No newline at end of file
+// export default toggleOpen(CommentList)
+export default toggleOpen(connect(createMapStateToProps, { addComment })(CommentList))
diff --git a/src/components/counter.js b/src/components/counter.js
index b49ee19..345c5f2 100644
--- a/src/components/counter.js
+++ b/src/components/counter.js
@@ -29,4 +29,4 @@ const mapStateToProps = state => ({
count: state.counter
})
-export default connect(mapStateToProps)(Counter)
\ No newline at end of file
+export default connect(mapStateToProps)(Counter)
diff --git a/src/components/filters/select.js b/src/components/filters/select.js
index 1a91857..c8dccb3 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(id => ({
+ label: articles[id].title,
+ value: id
}))
return