Comment.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { connect } from 'react-redux'
  2. import React, { useState } from 'react'
  3. import 'emoji-mart/css/emoji-mart.css'
  4. import { Comment, Avatar } from 'antd'
  5. import { CommentAction } from './Reply'
  6. import { CommentDate } from './CommentDate'
  7. import {
  8. actionAddSubCommentTypeSaga,
  9. actionFindSubCommentTypeSaga,
  10. } from '../../actions/typeSaga/postTypesSaga'
  11. import { Typography } from 'antd'
  12. import CommentAuthor from './CommentAuthor'
  13. import CommentAvatar from './CommentAvatar'
  14. import { ViewComment } from './SpoilerButton'
  15. const { Text } = Typography
  16. export const Comments = ({
  17. comments,
  18. postId,
  19. parentId,
  20. findSubComment,
  21. }) => {
  22. return (
  23. <>
  24. {comments?.length && Object.keys(comments[0])?.length > 1
  25. ?
  26. <ViewComment text={'View all '} count={comments?.length}
  27. textClosed={'Hide comments'}>
  28. {comments?.map((comment) => {
  29. return (
  30. <Comment
  31. key={comment?._id}
  32. author={
  33. <CommentAuthor owner={comment?.owner} />
  34. }
  35. actions={[<CommentAction commentId={comment?._id} />]}
  36. avatar={
  37. <CommentAvatar owner={comment?.owner} />
  38. }
  39. content={<p>{comment?.text}</p>}
  40. datetime={<CommentDate createdAt={comment?.createdAt} />}
  41. >
  42. <Comments
  43. postId={postId}
  44. comments={comment?.answers}
  45. parentId={comment?._id}
  46. findSubComment={findSubComment}
  47. />
  48. </Comment>
  49. )
  50. })}
  51. </ViewComment>
  52. :
  53. comments?.length && (
  54. <Text className='ButtonComment'
  55. type="secondary"
  56. strong
  57. style={{ margin: '0 auto' }}
  58. onClick={() => findSubComment(parentId)}
  59. >
  60. {/* __ View answers ({comments.length}) */}
  61. </Text>
  62. )}
  63. </>
  64. )
  65. }
  66. export const CCommentsOnePost = connect(
  67. (state) => ({
  68. postId: state.promise.onePost?.payload?._id,
  69. // comments: state?.post.onePost?.comments,
  70. addComment: state.promise?.addComment?.payload,
  71. addSubComment: state.promise?.addSubComment,
  72. }),
  73. {
  74. findSubComment: actionFindSubCommentTypeSaga,
  75. },
  76. )(Comments)