Like.js 2.5 KB

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