Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5908 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4265 stevensc 1
/* eslint-disable react/prop-types */
2
import React, { useEffect } from 'react'
3
import { useDispatch, useSelector } from 'react-redux'
4
import { fetchFeeds, setCurrentPage } from '../../../../redux/feed/feed.actions'
5
import EmptySection from '../../../../shared/empty-section/EmptySection'
6
import Spinner from '../../../../shared/loading-spinner/Spinner'
7
import ShareModal from '../../../components/share-modal/ShareModal'
5107 stevensc 8
import Feed from './Feed'
5901 stevensc 9
const PaginationComponent = React.lazy(() =>
10
  import('../../../../shared/pagination/PaginationComponent')
11
)
4265 stevensc 12
 
5907 stevensc 13
const FeedList = ({ feed, image }) => {
5901 stevensc 14
  const { allFeeds, timelineUrl, pages, currentPage, loading } = useSelector(
15
    (state) => state.feed
16
  )
4265 stevensc 17
  const dispatch = useDispatch()
18
 
5901 stevensc 19
  const fetchSpecificFeed = () =>
20
    dispatch(fetchFeeds(timelineUrl + '/feed/' + feed, 1))
4265 stevensc 21
 
22
  useEffect(() => {
23
    if (feed) {
24
      return fetchSpecificFeed()
25
    } else {
26
      return dispatch(fetchFeeds(timelineUrl, currentPage))
27
    }
5908 stevensc 28
  }, [timelineUrl, currentPage, feed])
4265 stevensc 29
 
30
  const onChangePageHandler = (currentPage) => {
5107 stevensc 31
    dispatch(setCurrentPage(currentPage))
4265 stevensc 32
    dispatch(fetchFeeds(timelineUrl, currentPage))
5107 stevensc 33
    window.scrollTo(0, 0)
34
  }
4265 stevensc 35
 
36
  if (loading) {
37
    return <Spinner />
38
  }
39
 
40
  if (!allFeeds.length) {
5901 stevensc 41
    return <EmptySection message="No hay publicaciones" />
4265 stevensc 42
  }
43
 
44
  return (
45
    <>
46
      {allFeeds.map((feed) => {
6406 stevensc 47
        return <Feed key={feed.feed_uuid} image={image} {...feed} />
4265 stevensc 48
      })}
4945 stevensc 49
      <React.Suspense fallback={null}>
50
        <PaginationComponent
51
          onChangePage={onChangePageHandler}
52
          pages={pages}
53
          isRow
54
          currentActivePage={currentPage}
55
        />
5906 stevensc 56
        <ShareModal timelineUrl={timelineUrl} currentPage={currentPage} />
4945 stevensc 57
      </React.Suspense>
4265 stevensc 58
    </>
59
  )
60
}
61
 
62
export default FeedList