Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
3993 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
 
6
import Spinner from "../../../shared/loading-spinner/Spinner";
4017 stevensc 7
import Feed from "../feed/FeedTemplate";
3993 stevensc 8
 
4017 stevensc 9
const ShareModal = React.lazy(() => import("../share-modal/ShareModal"))
10
const HomeNews = React.lazy(() => import("../home-section/HomeNews"))
11
const PeopleYouMayKnow = React.lazy(() => import("../../../shared/helpers/people-you-may-know/PeopleYouMayKnow"))
12
const PaginationComponent = React.lazy(() => import("../../../shared/pagination/PaginationComponent"))
13
 
3993 stevensc 14
const PATH = window.location.pathname
15
 
4017 stevensc 16
// Props object {routeTimeline, feed, image}
3993 stevensc 17
 
4017 stevensc 18
const FeedSection = ({ feed, image }) => {
19
 
3993 stevensc 20
  const { allFeeds, timelineUrl, pages, currentPage, loading } = useSelector((state) => state.feed)
21
  const dispatch = useDispatch()
22
 
23
 
24
  const fetchSpecificFeed = () => dispatch(fetchFeeds(timelineUrl + '/feed/' + feed, 1))
25
 
26
  useEffect(() => {
27
    if (feed) {
28
      return fetchSpecificFeed()
29
    } else {
30
      return dispatch(fetchFeeds(timelineUrl, currentPage))
31
    }
32
  }, []);
33
 
34
 
35
  const onChangePageHandler = (currentPage) => {
36
    dispatch(setCurrentPage(currentPage));
37
    dispatch(fetchFeeds(timelineUrl, currentPage))
38
    window.scrollTo(0, 0);
39
  };
40
 
41
  if (loading) return (
42
    <div className="w-100 h-100" style={{ display: "grid", placeItems: 'center' }}>
43
      <Spinner />
44
    </div>
45
  )
46
 
47
  return (
48
    <>
49
      {allFeeds.length
50
        ? allFeeds.map((feed, index) =>
51
          <>
52
            {
53
              (index === 5 && PATH.includes('dashboard')) &&
54
              <div className='d-block d-md-none'>
55
                <PeopleYouMayKnow />
56
              </div>
57
            }
58
            {
59
              (index === 8 && PATH.includes('dashboard')) &&
60
              < div className='d-block d-md-none'>
61
                <HomeNews />
62
              </div>
63
            }
4017 stevensc 64
            <Feed
3993 stevensc 65
              feed={feed}
66
              key={feed.feed_unique}
67
              owner_shared={feed.owner_shared}
68
              image={image}
4017 stevensc 69
            />
70
          </>
71
        )
3993 stevensc 72
        :
73
        <div style={{ display: 'grid', width: '100%', padding: '20px', placeItems: 'center' }}>
74
          <h2>No hay publicaciones</h2>
75
        </div>
76
      }
77
      <ShareModal
78
        timelineUrl={timelineUrl}
79
        currentPage={currentPage}
80
      />
81
      <PaginationComponent
82
        onChangePage={onChangePageHandler}
83
        pages={pages}
84
        isRow
85
        currentActivePage={currentPage}
86
      />
87
    </>
88
  );
89
};
90
 
91
export default React.memo(FeedSection);