Like.jsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { HeartOutlined, HeartFilled } from '@ant-design/icons'
  2. import {
  3. actionChangeLikeTypeSaga,
  4. actionChangeFeedLikeTypeSaga,
  5. } from '../../actions/typeSaga/likeTypesSaga'
  6. import { connect } from 'react-redux'
  7. import ModalLikes from './ModalLikes'
  8. export const Like = ({ my_Id, postId, likes = [], changeLike }) => {
  9. const likeId = likes.find((like) => like?.owner?._id === my_Id)?._id
  10. return (
  11. <>
  12. <div className='OneLike'>
  13. <p onClick={() => changeLike(likeId, postId)}
  14. style={{ margin: '0 auto' }}>
  15. {likeId ? (
  16. <HeartFilled style={{ color: 'red' }}
  17. className="Like" />
  18. ) : (
  19. <HeartOutlined className="Like" />
  20. )}
  21. </p>
  22. <ModalLikes likes={likes} myId={my_Id} />
  23. </div>
  24. </>
  25. )
  26. }
  27. const AllLikes = ({ my_Id, likes, changeLike, postId }) => (
  28. <Like my_Id={my_Id} likes={likes} postId={postId} changeLike={changeLike} />
  29. )
  30. export const CLike = connect(
  31. (state) => ({
  32. my_Id: state.auth?.payload?.sub?.id || '',
  33. }),
  34. {
  35. changeLike: actionChangeLikeTypeSaga,
  36. },
  37. )(AllLikes)
  38. export const CLikeFeed = connect(
  39. (state) => ({
  40. my_Id: state.auth?.payload?.sub?.id || '',
  41. }),
  42. {
  43. changeLike: actionChangeFeedLikeTypeSaga,
  44. },
  45. )(AllLikes)