Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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