Like.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { Avatar, Col, Row } from 'antd'
  2. import { ConstructorModal } from '../helpers'
  3. import { Link } from 'react-router-dom'
  4. import user from '../materials/user.png'
  5. import { HeartOutlined, HeartFilled } from '@ant-design/icons'
  6. import React, { useState } from 'react'
  7. export const Likes = ({ likes }) => {
  8. return (
  9. <>
  10. <div className="Modal">
  11. {likes &&
  12. likes?.map(({ owner: { _id, login, avatar } }) => (
  13. <Link to={`/profile/${_id}`}>
  14. <Row style={{margin:'10px'}}>
  15. <Col offset={1}>
  16. {avatar?.url ? (
  17. <Avatar
  18. style={{ width: '50px', height: '50px' }}
  19. src={'/' + avatar?.url}
  20. />
  21. ) : (
  22. <Avatar style={{ width: '50px', height: '50px' }} src={user} />
  23. )}
  24. </Col>
  25. <Col offset={2}>
  26. <h3> {login || 'Anon'}</h3>
  27. </Col>
  28. </Row>
  29. </Link>
  30. ))}
  31. </div>
  32. </>
  33. )
  34. }
  35. export const Like = ({
  36. my_Id,
  37. postId,
  38. addLike,
  39. deleteLike,
  40. likes = [],
  41. children,
  42. }) => {
  43. const likeId = likes.find((like) => like?.owner?._id === my_Id)?._id
  44. const changeLike = () =>
  45. likeId ? deleteLike(likeId, postId) : addLike(postId)
  46. const [isModalVisible, setIsModalVisible] = useState(false)
  47. const showModal = () => {
  48. setIsModalVisible(true)
  49. }
  50. return (
  51. <>
  52. <div style={{ display: 'flex' }}>
  53. <h2 onClick={changeLike}>
  54. {likeId ? (
  55. <HeartFilled
  56. style={{ cursor: 'pointer', fontSize: 'xx-large', color: 'red' }}
  57. />
  58. ) : (
  59. <HeartOutlined
  60. style={{ cursor: 'pointer', fontSize: 'xx-large' }}
  61. />
  62. )}
  63. </h2>
  64. {likes.length ? (
  65. <h3 style={{ cursor: 'pointer', paddingLeft: 8 }} onClick={showModal}>
  66. {' '}
  67. {likes.length} likes
  68. </h3>
  69. ) : (
  70. <h3 style={{ cursor: 'pointer', paddingLeft: 8 }}> 0 likes</h3>
  71. )}
  72. </div>
  73. <ConstructorModal
  74. title={'Likes'}
  75. isModalVisible={isModalVisible}
  76. setIsModalVisible={setIsModalVisible}
  77. >
  78. <Likes likes={likes} />
  79. </ConstructorModal>
  80. </>
  81. )
  82. }