Post.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import { Router, Route, Link, Redirect, Switch } from 'react-router-dom'
  2. import {
  3. actionAllPosts, actionOnePost, actionFindLikes, actionAddFullComment, actionGetFindLiked, actionFindSubComment,
  4. actionAddSubFullComment, actionDeleteFullLike, actionAddFullLike, actionAddLike, actionDeleteLike
  5. } from '../actions'
  6. import photoNotFound from '../materials/photoNotFound.png'
  7. import { LeftCircleFilled, RightCircleFilled, HeartOutlined,HeartTwoTone,HeartFilled } from '@ant-design/icons'
  8. import { Carousel,Avatar,Tooltip } from 'antd'
  9. import user from '../materials/user1.png'
  10. import { Provider, connect } from 'react-redux'
  11. import { Row, Col } from 'antd';
  12. import { Divider, Input, Button, Modal } from 'antd';
  13. import { EditOutlined } from '@ant-design/icons'
  14. import moment from 'moment';
  15. import {CComments, AddComment} from '../components/Post_Comment'
  16. import { ConstructorModal} from '../helpers'
  17. import React, { useMemo, useState, useEffect } from 'react'
  18. // const postId="625afa1d069dca48a822ffb0"
  19. export const Card = ({ post, onPost }) => (
  20. <>
  21. {/* <Link to={`/post/${postId}`} onClick={() => onPost(postId)}> */}
  22. {/* {console.log('post id', post?._id)}
  23. onClick={() => onPost(post?._id)}
  24. */}
  25. <Link to={`/post/${post?._id}`}>
  26. {post?.images && post?.images[0] && post.images[0]?.url ? (
  27. <img
  28. className="Card"
  29. src={ '/' + post.images[0].url}
  30. style={{minHeight:'150px', minWidth:'150px', maxWidth: '230px', maxHeight: '200px' }}
  31. />
  32. ) : (
  33. <img
  34. className="Card"
  35. src={photoNotFound}
  36. style={{ maxWidth: '230px', minHeight:'150px', minWidth:'150px' ,maxHeight: '200px' }}
  37. />
  38. )}
  39. {/* {console.log(post?._id)} */}
  40. </Link>
  41. </>
  42. )
  43. const SampleNextArrow = (props) => {
  44. const { className, style, onClick } = props
  45. return (
  46. <div
  47. className="carousel-control-next"
  48. style={{
  49. fontSize: '50px',
  50. color: '#a8a8a8',
  51. position: 'absolute',
  52. left: '100%',
  53. top: '50%',
  54. margin: 'auto',
  55. paddingLeft:'20px'
  56. }}
  57. onClick={onClick}
  58. >
  59. <RightCircleFilled />
  60. </div>
  61. )
  62. }
  63. const SamplePrevArrow = (props) => {
  64. const { className, style, onClick } = props
  65. return (
  66. <div
  67. className="carousel-control-prev"
  68. style={{
  69. color: '#a8a8a8',
  70. fontSize: '50px',
  71. position: 'absolute',
  72. margin: 'auto',
  73. right: '100%',
  74. top: '50%',
  75. paddingRight:'20px'
  76. }}
  77. onClick={onClick}
  78. >
  79. <LeftCircleFilled />
  80. </div>
  81. )
  82. }
  83. export const MyCarousel = ({ images = [] }) => {
  84. // console.log('IMAGES', images)
  85. return (
  86. <>
  87. <div className='MyCarousel'>
  88. <Carousel
  89. effect="fade"
  90. arrows
  91. nextArrow={<SampleNextArrow />}
  92. prevArrow={<SamplePrevArrow />}
  93. >
  94. {
  95. images
  96. ?
  97. (images.map((i, index) =>
  98. i?.url && (
  99. <div key={index}>
  100. <img
  101. key={index}
  102. className="PostImage"
  103. src={'/' + i?.url}
  104. style={{
  105. display: 'flex',
  106. alignItems: 'center',
  107. width: '50%',
  108. margin: '0 auto',
  109. maxWidth: '60%',
  110. height: '50%',
  111. minWidth: '40%',
  112. minHeight: '40%',
  113. maxHeight: '60%',
  114. marginBottom: '40px',
  115. }}
  116. />
  117. </div>
  118. )
  119. ))
  120. : (
  121. <div>
  122. <img
  123. className="PostImage"
  124. src={photoNotFound}
  125. style={{ maxWidth: '400px', maxHeight: '400px' }}
  126. />
  127. </div>
  128. )
  129. }
  130. </Carousel>
  131. </div>
  132. </>
  133. )
  134. }
  135. const Likes = ({ likes }) =>
  136. {
  137. return (
  138. <>
  139. <div className='Modal'>
  140. {
  141. likes &&
  142. likes?.map(({ owner:{_id, login, avatar} }) => (
  143. // <div style={{ display: 'flex', flexDirection:'row' }}>
  144. <Link to={`/profile/${_id}`}>
  145. <Row>
  146. <Col offset={1}>
  147. <Avatar
  148. style={{
  149. width: '50px',
  150. height: '50px',
  151. // marginRight: '30px',
  152. // position: 'absolute',
  153. }}
  154. src={'/' + avatar?.url || user}
  155. />
  156. </Col>
  157. <Col offset={2}>
  158. <h3 > {login || 'Anon'}</h3>
  159. </Col>
  160. </Row>
  161. </Link>
  162. ))
  163. }
  164. </div>
  165. </>
  166. )
  167. }
  168. const Like = ({ my_Id, postId, addLike, deleteLike, likes=[], children }) =>
  169. {
  170. const likeId = likes.find(like => like?.owner?._id === my_Id)?._id
  171. const changeLike = () => likeId ? deleteLike(likeId, postId) : addLike(postId)
  172. // console.log('likeId', likeId)
  173. const [isModalVisible, setIsModalVisible] = useState(false);
  174. const showModal = () => {
  175. setIsModalVisible(true);
  176. };
  177. return(
  178. <>
  179. <div style={{display:'flex'}}>
  180. <h3 onClick={changeLike}>
  181. {likeId ?
  182. <HeartFilled style={{cursor: 'pointer', fontSize:'xx-large', color:'red'}} />:
  183. <HeartOutlined style={{cursor: 'pointer', fontSize: 'xx-large' }} /> }
  184. </h3>
  185. {likes.length ?
  186. <h3 style={{cursor: 'pointer', paddingLeft: 8 }} onClick={showModal}> {likes.length} likes
  187. </h3>
  188. :
  189. '0 likes'}
  190. </div>
  191. <ConstructorModal title={'Likes'} isModalVisible={isModalVisible}
  192. setIsModalVisible={setIsModalVisible}>
  193. <Likes likes={likes}/>
  194. </ConstructorModal>
  195. </>
  196. )
  197. }
  198. export const PagePost = ({ my_Id, onePost, likes, addComment,
  199. addCommentReply, addLike, findSubComment, deleteLike,
  200. match: { params: { _id } },
  201. aboutUser: { avatar, login } = {}, onPost }) => {
  202. useEffect(() => {
  203. onPost(_id)
  204. console.log('ONE POST _ID',onePost?._id)
  205. }, [_id])
  206. return (
  207. <>
  208. <Row>
  209. <Col span={14}>
  210. {/* <div style={{display: 'flex'}}> */}
  211. <MyCarousel style={{position: 'absolute'}} images={onePost?.images} />
  212. <h3 style={{ textAlign: 'center', padding:'30px'}}>
  213. Created Post: {new Intl.DateTimeFormat('en-GB').format(onePost?.createdAt)}
  214. </h3>
  215. <div style={{marginLeft:'100px'}}>
  216. {/* <Col span={3} offset={2}> */}
  217. <Like my_Id={my_Id} addLike={addLike} deleteLike={deleteLike} likes={onePost?.likes} postId={onePost?._id}>
  218. <Likes likes={onePost?.likes} />
  219. </Like>
  220. {/* </Col> */}
  221. </div>
  222. </Col>
  223. <Col span={8}>
  224. <div style={{display: 'flex', flexDirection:'row'}}>
  225. {avatar ? (
  226. <Avatar
  227. style={{ width: '50px', height: '50px' }}
  228. src={ '/' + avatar?.url}
  229. />
  230. ) : (
  231. <Avatar style={{ width: '50px', height: '50px' }} src={user} />
  232. )
  233. }
  234. <h1 style={{ marginLeft:'20px'}}> {login}</h1>
  235. </div>
  236. <Divider/>
  237. <h2> Title: {onePost?.title || ''} </h2>
  238. <h2> Text: {onePost?.text || ''} </h2>
  239. <Divider>Comments</Divider>
  240. <div className="Scroll">
  241. <CComments comments={onePost?.comments || []} />
  242. </div>
  243. {/* <HeartTwoTone twoToneColor="#eb2f96" /> */}
  244. <AddComment addComment={addComment} onePost={onePost} />
  245. </Col>
  246. </Row>
  247. </>
  248. )
  249. }
  250. export const CPost = connect((state) => ({
  251. onePost: state.promise.onePost?.payload,
  252. my_Id: state.auth.payload.sub.id || '',
  253. aboutUser: state.profilePage?.aboutUser,
  254. addComment: state.promise?.addComment?.payload,
  255. addSubComment: state.promise?.addSubComment,
  256. }), {
  257. addLike: actionAddFullLike,
  258. findLikes: actionGetFindLiked,
  259. deleteLike: actionDeleteFullLike,
  260. addComment: actionAddFullComment,
  261. addCommentReply: actionAddSubFullComment,
  262. findLikes: actionFindLikes,
  263. onPost:actionOnePost
  264. })(PagePost)