Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 199 | Rev 697 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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