Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4271 | Ir a la última revisión | | 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}
51
            name={feed.owner_name}
52
            description=''
53
            message={feed.owner_description}
54
            photoUrl={image}
55
          />
56
        )
57
      })}
58
      <PaginationComponent
59
        onChangePage={onChangePageHandler}
60
        pages={pages}
61
        isRow
62
        currentActivePage={currentPage}
63
      />
64
      <ShareModal
65
        timelineUrl={timelineUrl}
66
        currentPage={currentPage}
67
      />
68
    </>
69
  )
70
}
71
 
72
export default FeedList