index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { Link } from 'react-router-dom'
  2. import { Avatar, Divider, Input, Button } from 'antd'
  3. import user from '../../materials/user.png'
  4. import { connect } from 'react-redux'
  5. import { Row, Col } from 'antd'
  6. import { CComments, CCommentsOnePost } from '../../components/comment/Comment'
  7. import { CPostEditor } from '../createAndEditPost'
  8. import AddComment from '../../components/comment/AddComment'
  9. import { actionFullOnePostSaga,actionAddFullCommentSaga } from '../../actions/typeSaga/postTypesSaga'
  10. import { CLike} from '../../components/like/Like'
  11. import { ConstructorModal } from '../../helpers'
  12. import React, { useState, useEffect } from 'react'
  13. import { LinkToUser } from '../../components/LinkToUser'
  14. import { MyCarousel } from '../../components/post/Carousel'
  15. import {EditMyPostButton} from '../../components/EditPostButton'
  16. export const PagePost = ({
  17. my_Id,
  18. onePost,
  19. addComment,
  20. match: {
  21. params: { _id },
  22. },
  23. aboutUser = {},
  24. onPost,
  25. }) => {
  26. const [isModalVisible, setIsModalVisible] = useState(false)
  27. useEffect(() => {
  28. onPost(_id)
  29. console.log('ONE POST _ID', onePost?._id)
  30. }, [_id])
  31. return (
  32. <>
  33. <Row>
  34. <Col span={14} style={{marginTop:'100px'}}>
  35. <ConstructorModal
  36. title={'Edit post'}
  37. isModalVisible={isModalVisible}
  38. setIsModalVisible={setIsModalVisible}
  39. >
  40. <CPostEditor />
  41. </ConstructorModal>
  42. <MyCarousel key={onePost?._id}
  43. style={{ position: 'absolute' }}
  44. images={onePost?.images}
  45. />
  46. <h3 style={{ textAlign: 'center', padding: '10px' }}>
  47. Created Post:{' '}
  48. {new Intl.DateTimeFormat('en-GB').format(onePost?.createdAt)}
  49. </h3>
  50. </Col>
  51. <Col span={8}>
  52. <div style={{ display: 'flex', flexDirection: 'row', marginTop:'100px' }}>
  53. <LinkToUser
  54. _id={onePost?.owner?._id}
  55. login={onePost?.owner?.login}
  56. avatar={onePost?.owner?.avatar}
  57. key={_id}
  58. size={50} padding={'0px'} />
  59. <Row span={1}>
  60. {my_Id === onePost?.owner?._id && <EditMyPostButton _id={_id} />}
  61. </Row>
  62. </div>
  63. <Divider />
  64. <h2> Title: {onePost?.title || ''} </h2>
  65. <h2> Text: {onePost?.text || ''} </h2>
  66. <Divider>Comments</Divider>
  67. <div className="Scroll">
  68. <CCommentsOnePost/>
  69. </div>
  70. <div style={{ display: 'flex', margin: '20px 0px' }}>
  71. <CLike likes={onePost?.likes} postId={onePost?._id} />
  72. <AddComment addComment={addComment}
  73. style={{
  74. position: 'absolute',
  75. bottom: "120px", right: "30px"
  76. }}
  77. width={'40%'}
  78. postId={onePost?._id} />
  79. </div>
  80. </Col>
  81. </Row>
  82. </>
  83. )
  84. }
  85. export const CPost = connect(
  86. (state) => ({
  87. onePost: state?.post.onePost,
  88. my_Id: state.auth.payload?.sub?.id || '',
  89. aboutUser: state.userData?.aboutUser,
  90. }),
  91. {
  92. addComment: actionAddFullCommentSaga,
  93. // addCommentReply: actionAddSubFullComment,
  94. onPost: actionFullOnePostSaga,
  95. },
  96. )(PagePost)