Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4271 | Rev 5107 | Ir a la última revisión | | 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'
4945 stevensc 8
const PaginationComponent = React.lazy(() => import('../../../../shared/pagination/PaginationComponent'))
4265 stevensc 9
import Feed from './Feed'
10
 
11
const FeedList = ({
12
  feed = {},
13
  image = ''
14
}) => {
15
  const { allFeeds, timelineUrl, pages, currentPage, loading } = useSelector((state) => state.feed)
16
  const dispatch = useDispatch()
17
 
18
  const fetchSpecificFeed = () => dispatch(fetchFeeds(timelineUrl + '/feed/' + feed, 1))
19
 
20
  useEffect(() => {
21
    if (feed) {
22
      return fetchSpecificFeed()
23
    } else {
24
      return dispatch(fetchFeeds(timelineUrl, currentPage))
25
    }
26
  }, []);
27
 
28
  const onChangePageHandler = (currentPage) => {
29
    dispatch(setCurrentPage(currentPage));
30
    dispatch(fetchFeeds(timelineUrl, currentPage))
31
    window.scrollTo(0, 0);
32
  };
33
 
34
  if (loading) {
35
    return <Spinner />
36
  }
37
 
38
  if (!allFeeds.length) {
39
    return <EmptySection message='No hay publicaciones' />
40
  }
41
 
42
  return (
43
    <>
44
      {allFeeds.map((feed) => {
45
        return (
46
          <Feed
47
            key={feed.feed_unique}
4271 stevensc 48
            image={image}
49
            {...feed}
4265 stevensc 50
          />
51
        )
52
      })}
4945 stevensc 53
      <React.Suspense fallback={null}>
54
        <PaginationComponent
55
          onChangePage={onChangePageHandler}
56
          pages={pages}
57
          isRow
58
          currentActivePage={currentPage}
59
        />
60
      </React.Suspense>
4265 stevensc 61
      <ShareModal
62
        timelineUrl={timelineUrl}
63
        currentPage={currentPage}
64
      />
65
    </>
66
  )
67
}
68
 
69
export default FeedList