index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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,useParams} 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. const { _id } = useParams();
  25. useEffect(() => {
  26. onAboutUser(_id)
  27. // console.log('USER DATA ', login, _id)
  28. }, [_id])
  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. <>
  90. <CEditSetting />
  91. </>
  92. ) : (
  93. <CSubscribe />
  94. )}
  95. </div>
  96. </Row>
  97. </section>
  98. </Col>
  99. </Row>
  100. <Row>
  101. <Col span={17} offset={4}>
  102. <div
  103. style={{
  104. display: 'flex',
  105. flexWrap: 'wrap',
  106. // padding: '20px',
  107. margin: '20px',
  108. }}
  109. >
  110. {(allPosts || [])?.map((item) => (
  111. <Card post={item} onPost={onPost} />
  112. ))}
  113. </div>
  114. </Col>
  115. </Row>
  116. </>
  117. )
  118. }
  119. export const CPageAboutUser = connect(
  120. (state) => ({
  121. my_Id: state.auth?.payload?.sub?.id,
  122. aboutUser: state.userData?.aboutUser,
  123. countAllPostsUser: state.promise?.countAllPostsUser?.payload,
  124. allPosts: state.userData?.allPosts,
  125. }),
  126. {
  127. onAboutUser: actionFullProfilePageUser,
  128. onPost: actionOnePost,
  129. // onPageData: actionFullProfilePageUser,
  130. },
  131. )(PageAboutUser)