Comment.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. style={{ overflowY: 'none' }}
  28. textClosed={'Hide comments'}>
  29. {comments?.map((comment) => {
  30. return (
  31. <Comment
  32. key={comment?._id}
  33. author={
  34. <CommentAuthor owner={comment?.owner} />
  35. }
  36. actions={[<CommentAction commentId={comment?._id} />]}
  37. avatar={
  38. <CommentAvatar owner={comment?.owner} />
  39. }
  40. content={<p>{comment?.text}</p>}
  41. datetime={<CommentDate createdAt={comment?.createdAt} />}
  42. >
  43. <Comments
  44. postId={postId}
  45. comments={comment?.answers}
  46. parentId={comment?._id}
  47. findSubComment={findSubComment}
  48. />
  49. </Comment>
  50. )
  51. })}
  52. </ViewComment>
  53. :
  54. comments?.length && (
  55. <Text className='ButtonComment'
  56. type="secondary"
  57. strong
  58. style={{ margin: '0 auto' }}
  59. onClick={() => findSubComment(parentId)}
  60. >
  61. {/* __ View answers ({comments.length}) */}
  62. </Text>
  63. )}
  64. </>
  65. )
  66. }
  67. export const CCommentsOnePost = connect(
  68. (state) => ({
  69. postId: state.promise.onePost?.payload?._id,
  70. // comments: state?.post.onePost?.comments,
  71. addComment: state.promise?.addComment?.payload,
  72. addSubComment: state.promise?.addSubComment,
  73. }),
  74. {
  75. findSubComment: actionFindSubCommentTypeSaga,
  76. },
  77. )(Comments)
  78. // export const CCommentsForFeed = connect(
  79. // (state) => ({
  80. // // postId: state.promise.onePost?.payload?._id,
  81. // addComment: state.promise?.addComment?.payload,
  82. // addSubComment: state.promise?.addSubComment,
  83. // }),
  84. // {
  85. // addCommentReply: actionAddSubFullComment,
  86. // findSubComment: actionFindSubComment,
  87. // },
  88. // )(Comments)