Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1231 | Rev 1650 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'

import Feed from '../feed-template/Feed'
import Spinner from '@app/components/UI/Spinner'
import EmptySection from '@app/components/UI/EmptySection'
import { fetchFeeds, setCurrentPage } from '@app/redux/feed/feed.actions'

const PaginationComponent = React.lazy(() =>
  import('../../../UI/PaginationComponent')
)

const FeedList = ({ feed, image }) => {
  const { allFeeds, timelineUrl, pages, currentPage, loading } = useSelector(
    ({ feed }) => feed
  )
  const dispatch = useDispatch()

  const fetchSpecificFeed = () =>
    dispatch(fetchFeeds(timelineUrl + '/feed/' + feed, 1))

  const onChangePageHandler = (currentPage) => {
    dispatch(setCurrentPage(currentPage))
    window.scrollTo(0, 0)
  }

  useEffect(() => {
    dispatch(setCurrentPage(1))
  }, [])

  useEffect(() => {
    feed ? fetchSpecificFeed() : dispatch(fetchFeeds(timelineUrl, currentPage))
  }, [timelineUrl, currentPage, feed])

  if (loading) {
    return <Spinner />
  }

  if (!allFeeds.length) {
    return <EmptySection message='No hay publicaciones' />
  }

  return (
    <>
      {allFeeds.map((feed) => {
        return <Feed key={feed.feed_uuid} image={image} {...feed} />
      })}
      <React.Suspense fallback={null}>
        <PaginationComponent
          pages={pages}
          currentActivePage={currentPage}
          onChangePage={onChangePageHandler}
          isRow
        />
      </React.Suspense>
    </>
  )
}

export default FeedList