index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { actionOnePost, actionUploadFile } from '../../actions'
  2. import user from '../../materials/user.png'
  3. import React, { useState, useEffect } from 'react'
  4. import { Card } from '../../components/PostCard'
  5. import ListOfUsers from '../../components/ListOfUsers'
  6. import { connect } from 'react-redux'
  7. import { Avatar, Button } from 'antd'
  8. import { actionFullProfilePageUser } from '../../redux/saga'
  9. import { Row, Col } from 'antd'
  10. import { CSubscribe } from '../../components/Subscribe'
  11. import { CEditSetting } from '../setting'
  12. import { Link} from 'react-router-dom'
  13. export const PageAboutUser = ({
  14. match: {
  15. params: { _id },
  16. },
  17. my_Id,
  18. aboutUser: { login, nick, createdAt, avatar, followers, following } = {},
  19. allPosts,
  20. onPost,
  21. onAboutUser,
  22. countAllPostsUser,
  23. }) => {
  24. useEffect(() => {
  25. onAboutUser(_id)
  26. // console.log('USER DATA ', login, _id)
  27. }, [_id])
  28. // const { _id } = useParams();
  29. const checkMyId = _id === my_Id
  30. return (
  31. <>
  32. <Row>
  33. <Col span={12} offset={6}>
  34. <section className="AboutMe">
  35. <Row>
  36. {avatar?.url ? (
  37. <Avatar
  38. style={{
  39. marginRight: '20px',
  40. width: '150px',
  41. height: '150px',
  42. }}
  43. src={'/' + avatar?.url}
  44. />
  45. ) : (
  46. <Avatar
  47. style={{
  48. marginRight: '20px',
  49. width: '150px',
  50. height: '150px',
  51. }}
  52. src={user}
  53. />
  54. )}
  55. <div className="Info">
  56. {login ? <h1> {login}</h1> : <h1> {'Anon'}</h1>}
  57. <h3>
  58. Created Account:{' '}
  59. {new Intl.DateTimeFormat('en-GB').format(createdAt)}
  60. </h3>
  61. <div style={{ display: 'flex' }}>
  62. {countAllPostsUser > 0 ? (
  63. <div
  64. style={{
  65. display: 'flex',
  66. justifyContent: 'space-between',
  67. }}
  68. >
  69. <h3> {countAllPostsUser} posts </h3>
  70. </div>
  71. ) : (
  72. <h3> 0 posts </h3>
  73. )}
  74. <ListOfUsers
  75. listResult={followers}
  76. listUsers={followers}
  77. onPageData={onAboutUser}
  78. text={'followers'}
  79. />
  80. <ListOfUsers
  81. listResult={following}
  82. listUsers={following}
  83. onPageData={onAboutUser}
  84. text={'following'}
  85. />
  86. </div>
  87. <h3> nick: {nick == null ? login : nick}</h3>
  88. {checkMyId ?
  89. <CEditSetting />
  90. :
  91. <CSubscribe />
  92. }
  93. </div>
  94. </Row>
  95. </section>
  96. </Col>
  97. </Row>
  98. <Row>
  99. <Col span={17} offset={4}>
  100. <div
  101. style={{
  102. display: 'flex',
  103. flexWrap: 'wrap',
  104. // padding: '20px',
  105. margin: '20px',
  106. }}
  107. >
  108. {(allPosts || [])?.map((item) => (
  109. <Card post={item} onPost={onPost} />
  110. ))}
  111. </div>
  112. </Col>
  113. </Row>
  114. </>
  115. )
  116. }
  117. export const CPageAboutUser = connect(
  118. (state) => ({
  119. my_Id: state.auth?.payload?.sub?.id,
  120. aboutUser: state.userData?.aboutUser,
  121. countAllPostsUser: state.promise?.countAllPostsUser?.payload,
  122. allPosts: state.userData?.allPosts,
  123. }),
  124. {
  125. onAboutUser: actionFullProfilePageUser,
  126. onPost: actionOnePost,
  127. // onPageData: actionFullProfilePageUser,
  128. },
  129. )(PageAboutUser)