Post.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { Link } from 'react-router-dom'
  2. import {
  3. actionAddFullComment,
  4. actionAddSubFullComment,
  5. actionDeleteFullLike,
  6. actionAddFullLike,
  7. } from '../actions'
  8. import { Avatar, Divider, Input, Button } from 'antd'
  9. import user from '../materials/user.png'
  10. import { connect } from 'react-redux'
  11. import { Row, Col } from 'antd'
  12. import { CComments, AddComment } from './Comment'
  13. import { CPostEditor } from '../pages/createAndEditPost'
  14. import { actionFullOnePost } from '../redux/reducers/post/postReducer'
  15. import { CLike} from './Like'
  16. import { ConstructorModal } from '../helpers'
  17. import React, { useState, useEffect } from 'react'
  18. import {
  19. actionAddFullCommentFeed,
  20. } from '../redux/thunk'
  21. import { LinkToUser } from './LinkToUser'
  22. import { MyCarousel } from './Carousel'
  23. const EditMyPost = ({ _id }) => {
  24. return (
  25. <>
  26. <Link to={`/edit/post/${_id}`}>
  27. <Button
  28. style={{ marginLeft: '200px',marginTop:'10px', width: '100px' }}
  29. size="large"
  30. type="primary"
  31. >
  32. Edit Post
  33. </Button>
  34. </Link>
  35. </>
  36. )
  37. }
  38. export const PagePost = ({
  39. my_Id,
  40. onePost,
  41. addComment,
  42. match: {
  43. params: { _id },
  44. },
  45. aboutUser = {},
  46. onPost,
  47. }) => {
  48. const [isModalVisible, setIsModalVisible] = useState(false)
  49. useEffect(() => {
  50. onPost(_id)
  51. console.log('ONE POST _ID', onePost?._id)
  52. }, [_id])
  53. return (
  54. <>
  55. <Row>
  56. <Col span={14} style={{marginTop:'100px'}}>
  57. <ConstructorModal
  58. title={'Edit post'}
  59. isModalVisible={isModalVisible}
  60. setIsModalVisible={setIsModalVisible}
  61. >
  62. <CPostEditor />
  63. </ConstructorModal>
  64. <MyCarousel key={onePost?._id}
  65. style={{ position: 'absolute' }}
  66. images={onePost?.images}
  67. />
  68. <h3 style={{ textAlign: 'center', padding: '10px' }}>
  69. Created Post:{' '}
  70. {new Intl.DateTimeFormat('en-GB').format(onePost?.createdAt)}
  71. </h3>
  72. </Col>
  73. <Col span={8}>
  74. <div style={{ display: 'flex', flexDirection: 'row', marginTop:'100px' }}>
  75. <LinkToUser
  76. _id={onePost?.owner?._id}
  77. login={onePost?.owner?.login}
  78. avatar={onePost?.owner?.avatar}
  79. key={_id}
  80. size={50} padding={'0px'} />
  81. <Row span={1}>
  82. {my_Id === onePost?.owner?._id && <EditMyPost _id={_id} />}
  83. </Row>
  84. </div>
  85. <Divider />
  86. <h2> Title: {onePost?.title || ''} </h2>
  87. <h2> Text: {onePost?.text || ''} </h2>
  88. <Divider>Comments</Divider>
  89. <div className="Scroll">
  90. <CComments
  91. postId={onePost?._id}
  92. comments={onePost?.comments || []}
  93. />
  94. </div>
  95. <div style={{ display: 'flex', margin: '40px 10px' }}>
  96. <CLike likes={onePost?.likes} postId={onePost?._id} />
  97. <AddComment addComment={addComment} postId={onePost?._id} />
  98. </div>
  99. </Col>
  100. </Row>
  101. </>
  102. )
  103. }
  104. export const CPost = connect(
  105. (state) => ({
  106. onePost: state.promise?.onePost?.payload,
  107. my_Id: state.auth.payload?.sub?.id || '',
  108. aboutUser: state.profilePage?.aboutUser,
  109. addComment: state.promise?.addComment?.payload,
  110. }),
  111. {
  112. addComment: actionAddFullCommentFeed,
  113. addCommentReply: actionAddSubFullComment,
  114. onPost: actionFullOnePost,
  115. },
  116. )(PagePost)