diff --git a/package.json b/package.json index 7672a70..6fa83d2 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "lodash": "^4.17.10", "prop-types": "^15.6.2", "react": "^16.5.2", "react-addons-css-transition-group": "^15.6.2", @@ -12,7 +13,8 @@ "react-scripts": "2.0.4", "react-select": "^2.1.0", "redux": "^4.0.1", - "reselect": "^4.0.0" + "reselect": "^4.0.0", + "uuid": "^3.3.2" }, "scripts": { "start": "react-scripts start", diff --git a/src/ac/index.js b/src/ac/index.js index 0e15a38..d13453d 100644 --- a/src/ac/index.js +++ b/src/ac/index.js @@ -13,10 +13,10 @@ export function increment() { } } -export function deleteArticle(id) { +export function deleteArticle(articleId) { return { type: DELETE_ARTICLE, - payload: { id } + payload: { articleId } } } @@ -41,9 +41,9 @@ export function addCommentToList(payload) { } } -export function addCommentToArticle(id) { +export function addCommentToArticle(payload) { return { type: ADD_COMMENT_TO_ARTICLE, - payload: { id } + payload } } diff --git a/src/components/article/index.js b/src/components/article/index.js index 981a98d..c56f31a 100644 --- a/src/components/article/index.js +++ b/src/components/article/index.js @@ -3,7 +3,6 @@ import CSSTransition from 'react-addons-css-transition-group' import PropTypes from 'prop-types' import { connect } from 'react-redux' import CommentList from '../comment-list' -import { createArticleSelector } from '../../selectors' import { deleteArticle } from '../../ac' import './style.css' @@ -70,15 +69,7 @@ class Article extends PureComponent { } } -const createMapStateToProps = () => { - const articleSelector = createArticleSelector() - - return (state, ownProps) => ({ - articles: articleSelector(state, ownProps) - }) -} - export default connect( - createMapStateToProps, + null, { deleteArticle } )(Article) diff --git a/src/components/comment-list/index.js b/src/components/comment-list/index.js index 166a580..c3df899 100644 --- a/src/components/comment-list/index.js +++ b/src/components/comment-list/index.js @@ -1,3 +1,5 @@ +import uuidv4 from 'uuid/v4' + import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' @@ -16,7 +18,6 @@ class CommentList extends Component { } state = { - id: 'ratatata', comment: null, user: null } @@ -47,11 +48,11 @@ class CommentList extends Component { } getBody() { - const { comments = [], isOpen } = this.props - const { id, text, user } = this.state + const { articleId, comments = [], isOpen } = this.props + const { text, user } = this.state if (!isOpen) return null - // TODO Генерировать id + // TODO Вынести форму добавления комментария в отдельную компоненту return (
{comments.length ? ( @@ -72,8 +73,9 @@ class CommentList extends Component { />