From 0cc6d307879787b28c087f371cf5412a9aca3b26 Mon Sep 17 00:00:00 2001 From: Pawlord Date: Thu, 17 Apr 2025 19:49:00 +0300 Subject: [PATCH 1/7] completed task 1 --- src/app/article/index.js | 11 ++- src/components/button/index.js | 5 +- src/components/comment-form/index.js | 27 +++++++ src/components/comment-form/style.css | 23 ++++++ src/components/comment-list/index.js | 38 +++++++++ src/components/comment-list/style.css | 5 ++ src/components/comment-non-session/index.js | 19 +++++ src/components/comment-non-session/style.css | 7 ++ src/components/comment/index.js | 39 +++++++++ src/components/comment/style.css | 38 +++++++++ src/components/comments-layout/index.js | 19 +++++ src/components/comments-layout/style.css | 10 +++ src/containers/catalog-filter/index.js | 1 - src/containers/comments/index.js | 64 +++++++++++++++ src/store-redux/comments/actions.js | 85 ++++++++++++++++++++ src/store-redux/comments/reducer.js | 47 +++++++++++ src/store-redux/exports.js | 1 + src/utils/format-date.js | 12 +++ 18 files changed, 447 insertions(+), 4 deletions(-) create mode 100644 src/components/comment-form/index.js create mode 100644 src/components/comment-form/style.css create mode 100644 src/components/comment-list/index.js create mode 100644 src/components/comment-list/style.css create mode 100644 src/components/comment-non-session/index.js create mode 100644 src/components/comment-non-session/style.css create mode 100644 src/components/comment/index.js create mode 100644 src/components/comment/style.css create mode 100644 src/components/comments-layout/index.js create mode 100644 src/components/comments-layout/style.css create mode 100644 src/containers/comments/index.js create mode 100644 src/store-redux/comments/actions.js create mode 100644 src/store-redux/comments/reducer.js create mode 100644 src/utils/format-date.js diff --git a/src/app/article/index.js b/src/app/article/index.js index 54f037b64..21642c145 100644 --- a/src/app/article/index.js +++ b/src/app/article/index.js @@ -1,4 +1,4 @@ -import { memo, useCallback } from 'react'; +import { memo, useCallback, useMemo } from 'react'; import { useParams } from 'react-router-dom'; import useStore from '../../hooks/use-store'; import useTranslate from '../../hooks/use-translate'; @@ -13,7 +13,9 @@ import TopHead from '../../containers/top-head'; import { useDispatch, useSelector } from 'react-redux'; import shallowequal from 'shallowequal'; import articleActions from '../../store-redux/article/actions'; +import commentActions from '../../store-redux/comments/actions'; import HeadLayout from '../../components/head-layout'; +import Comments from '../../containers/comments'; function Article() { const store = useStore(); @@ -26,12 +28,15 @@ function Article() { useInit(() => { //store.actions.article.load(params.id); dispatch(articleActions.load(params.id)); + dispatch(commentActions.load(params.id)) }, [params.id]); const select = useSelector( state => ({ article: state.article.data, waiting: state.article.waiting, + comments: state.comments.comments, + commentsWaiting: state.comments.waiting, }), shallowequal, ); // Нужно указать функцию для сравнения свойства объекта, так как хуком вернули объект @@ -56,6 +61,10 @@ function Article() { + + + + ); diff --git a/src/components/button/index.js b/src/components/button/index.js index 7d1d3d05c..6502f1721 100644 --- a/src/components/button/index.js +++ b/src/components/button/index.js @@ -3,12 +3,12 @@ import PropTypes from 'prop-types'; import { cn as bem } from '@bem-react/classname'; import './style.css'; -function Button({ onClick = () => {}, title, style, type = 'button' }) { +function Button({ onClick = () => { }, title, style, type = 'button', className }) { const cn = bem('Button'); return (
- +
); } @@ -18,6 +18,7 @@ Button.propTypes = { title: PropTypes.string, style: PropTypes.oneOf(['text', 'primary', 'delete', 'outline']), type: PropTypes.oneOf(['button', 'submit']), + className: PropTypes.string, }; export default memo(Button); diff --git a/src/components/comment-form/index.js b/src/components/comment-form/index.js new file mode 100644 index 000000000..6891bf742 --- /dev/null +++ b/src/components/comment-form/index.js @@ -0,0 +1,27 @@ +import React, { useState } from 'react'; +import './style.css'; +import PropTypes from 'prop-types'; +import Button from '../button'; + +function CommentForm({ onSubmit }) { + const [commentText, setCommentText] = useState(''); + + const handleSubmit = e => { + e.preventDefault(); + onSubmit(commentText) + } + + return ( +
+

Новый комментарий

+