AddComment.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { Picker } from 'emoji-mart'
  2. import 'emoji-mart/css/emoji-mart.css'
  3. import React, { useState } from 'react'
  4. import { Input, Button } from 'antd'
  5. import { SmileOutlined,SmileFilled } from '@ant-design/icons'
  6. export const AddComment = ({ addComment, postId,style, width }) => {
  7. const [text, setComment] = useState('')
  8. const [showEmojiPicker, setShowEmojiPicker] = useState(false)
  9. console.log('show stickers', showEmojiPicker)
  10. const handleOK = () =>
  11. setShowEmojiPicker(!showEmojiPicker)
  12. const addEmoji = ({ native }) =>
  13. setComment((text + ' ' + native).trim())
  14. return (
  15. <>
  16. {showEmojiPicker && (
  17. <Picker
  18. style={style}
  19. theme="light"
  20. native={true}
  21. showPreview={false}
  22. showSkinTones={false}
  23. onSelect={(native) =>
  24. addEmoji(native)}
  25. />
  26. )}
  27. <Input
  28. style={{
  29. display: 'flex',
  30. width,
  31. margin:"0 10px"
  32. }}
  33. size="large"
  34. placeholder="Add a comment..."
  35. value={text}
  36. onChange={(e) => {
  37. setComment(e.target.value)
  38. }}
  39. onPressEnter={(e) => {
  40. setComment(e.target.value)
  41. }}
  42. />
  43. {
  44. !showEmojiPicker ?
  45. <SmileOutlined
  46. className="smile-btn"
  47. style={{ fontSize: 'xx-large', marginRight: '15px' }}
  48. onClick={handleOK}
  49. />
  50. :
  51. <SmileFilled
  52. className="smile-btn"
  53. style={{ color:'#108ee9',fontSize: 'xx-large', marginRight: '30px' }}
  54. onClick={handleOK}
  55. />
  56. }
  57. <Button
  58. size="large"
  59. disabled={text.length < 1}
  60. type="primary"
  61. onClick={(e) => {
  62. addComment(postId, text)
  63. && setComment(e.target.value = '') &&
  64. setShowEmojiPicker(false)
  65. }}
  66. >
  67. {' '}
  68. Publish{' '}
  69. </Button>
  70. </>
  71. )
  72. }
  73. export const SpoilerButton = ({ text, close, children, style }) => {
  74. const [opened, setOpened] = useState(close)
  75. return (
  76. <>
  77. <Button
  78. onClick={() => {
  79. setOpened(!opened)
  80. }}
  81. style={style}
  82. >
  83. {text}
  84. </Button>
  85. {opened && children}
  86. </>
  87. )
  88. }
  89. const CommentForReply = ({ addCommentReply, commentId, postId }) => {
  90. const [comment, setComment] = useState('')
  91. return (
  92. <>
  93. <div
  94. style={{
  95. display: 'flex',
  96. flexDirection: 'row',
  97. width: '100%',
  98. padding: '15px',
  99. marginLeft: '40px',
  100. }}
  101. >
  102. <Input
  103. placeholder="Add a comment..."
  104. value={comment}
  105. onChange={(e) => {
  106. setComment(e.target.value)
  107. }}
  108. />
  109. <Button
  110. disabled={comment.length < 1}
  111. type="primary"
  112. onClick={() => addCommentReply(postId, commentId, comment)}
  113. >
  114. {' '}
  115. Publish{' '}
  116. </Button>
  117. </div>
  118. </>
  119. )
  120. }