index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 {actionClearAllPostsType,actionPostsPortionTypeSaga} from '../../redux/reducers/userProfileReducer'
  11. import { CSubscribe } from '../../components/Subscribe'
  12. import { CEditSetting } from '../setting'
  13. import { Link} from 'react-router-dom'
  14. import load from '../../materials/load.gif'
  15. export const PageAboutUser = ({
  16. match: {
  17. params: { _id },
  18. },
  19. my_Id,
  20. aboutUser: { login, nick, createdAt, avatar, followers, following } = {},
  21. allPosts,
  22. onPost,
  23. onAboutUser,
  24. countPosts,
  25. onClearPosts,
  26. onUserPosts,
  27. userPostPromise
  28. }) => {
  29. const [checkScroll, setScroll] = useState(true)
  30. useEffect(() => {
  31. onAboutUser(_id)
  32. }, [_id])
  33. useEffect(() => {
  34. if (checkScroll) {
  35. console.log('попало в новую порцию постов')
  36. onUserPosts(_id)
  37. }
  38. setScroll(false)
  39. }, [checkScroll])
  40. useEffect(() => {
  41. document.addEventListener('scroll', scrollHandler)
  42. return () => {
  43. document.removeEventListener('scroll', scrollHandler)
  44. onClearPosts()
  45. }
  46. }, [])
  47. console.log('check scroll ', checkScroll)
  48. useEffect(() => {
  49. document.addEventListener('scroll', scrollHandler)
  50. }, [allPosts?.length])
  51. const scrollHandler = (e) => {
  52. if (e.target.documentElement.scrollHeight -
  53. (e.target.documentElement.scrollTop + window.innerHeight) < 200) {
  54. console.log('SCROLL HANDLER', checkScroll)
  55. setScroll(true)
  56. document.removeEventListener('scroll', scrollHandler)
  57. }
  58. }
  59. const checkMyId = _id === my_Id
  60. return (
  61. <>
  62. <Row>
  63. <Col span={12} offset={6}>
  64. <section className="AboutMe">
  65. <Row>
  66. {avatar?.url ? (
  67. <Avatar
  68. style={{
  69. marginRight: '20px',
  70. width: '150px',
  71. height: '150px',
  72. }}
  73. src={'/' + avatar?.url}
  74. />
  75. ) : (
  76. <Avatar
  77. style={{
  78. marginRight: '20px',
  79. width: '150px',
  80. height: '150px',
  81. }}
  82. src={user}
  83. />
  84. )}
  85. <div className="Info">
  86. {login ? <h1> {login}</h1> : <h1> {'Anon'}</h1>}
  87. <h3>
  88. Created Account:{' '}
  89. {new Intl.DateTimeFormat('en-GB').format(createdAt)}
  90. </h3>
  91. <div style={{ display: 'flex' }}>
  92. {countPosts > 0 ? (
  93. <div
  94. style={{
  95. display: 'flex',
  96. justifyContent: 'space-between',
  97. }}
  98. >
  99. <h3> {countPosts} posts </h3>
  100. </div>
  101. ) : (
  102. <h3> 0 posts </h3>
  103. )}
  104. <ListOfUsers
  105. listResult={followers}
  106. listUsers={followers}
  107. onPageData={onAboutUser}
  108. text={'followers'}
  109. />
  110. <ListOfUsers
  111. listResult={following}
  112. listUsers={following}
  113. onPageData={onAboutUser}
  114. text={'following'}
  115. />
  116. </div>
  117. <h3> nick: {nick == null ? login : nick}</h3>
  118. {checkMyId ?
  119. <CEditSetting />
  120. :
  121. <CSubscribe />
  122. }
  123. </div>
  124. </Row>
  125. </section>
  126. </Col>
  127. </Row>
  128. <Row>
  129. <Col span={17} offset={4}>
  130. <div
  131. style={{
  132. display: 'flex',
  133. flexWrap: 'wrap',
  134. // padding: '20px',
  135. margin: '20px',
  136. }}
  137. >
  138. {(allPosts || [])?.map((item) => (
  139. <Card post={item} onPost={onPost} />
  140. ))}
  141. </div>
  142. </Col>
  143. </Row>
  144. {(userPostPromise?.status == "PENDING") &&
  145. <img style={{
  146. display: 'block', margin: '0 auto',
  147. marginBottom: '200px', padding: '10px'
  148. }}
  149. src={load} width="100" height="100" />
  150. }
  151. </>
  152. )
  153. }
  154. export const CPageAboutUser = connect(
  155. (state) => ({
  156. my_Id: state.auth?.payload?.sub?.id,
  157. aboutUser: state.userData?.aboutUser,
  158. countPosts: state?.promise?.countPosts?.payload,
  159. allPosts: state.userData?.allPosts,
  160. userPostPromise:state.promise?.allPosts
  161. }),
  162. {
  163. onAboutUser: actionFullProfilePageUser,
  164. onPost: actionOnePost,
  165. onClearPosts: actionClearAllPostsType,
  166. onUserPosts:actionPostsPortionTypeSaga
  167. // onPageData: actionFullProfilePageUser,
  168. },
  169. )(PageAboutUser)