Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4912 | Rev 5414 | 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 */
5106 stevensc 2
import React, { Suspense, 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 Feed from '../feed/FeedTemplate'
4017 stevensc 8
 
5106 stevensc 9
const ShareModal = React.lazy(() => import('../share-modal/ShareModal'))
10
const PaginationComponent = React.lazy(() => import('../../../shared/pagination/PaginationComponent'))
11
 
4022 stevensc 12
const isDashboard = window.location.pathname.includes('dashboard')
4912 stevensc 13
const isMobile = window.innerWidth < 768
3993 stevensc 14
 
4017 stevensc 15
const FeedSection = ({ feed, image }) => {
4222 stevensc 16
  const { allFeeds, timelineUrl, pages, currentPage, loading } = useSelector((state) => state.feed)
3993 stevensc 17
  const dispatch = useDispatch()
18
 
19
  const fetchSpecificFeed = () => dispatch(fetchFeeds(timelineUrl + '/feed/' + feed, 1))
20
 
21
  useEffect(() => {
22
    if (feed) {
23
      return fetchSpecificFeed()
24
    } else {
25
      return dispatch(fetchFeeds(timelineUrl, currentPage))
26
    }
5106 stevensc 27
  }, [])
3993 stevensc 28
 
29
  const onChangePageHandler = (currentPage) => {
5106 stevensc 30
    dispatch(setCurrentPage(currentPage))
3993 stevensc 31
    dispatch(fetchFeeds(timelineUrl, currentPage))
5106 stevensc 32
    window.scrollTo(0, 0)
33
  }
3993 stevensc 34
 
4222 stevensc 35
  if (loading) {
36
    return <Spinner />
37
  }
38
 
3993 stevensc 39
  return (
40
    <>
41
      {allFeeds.length
4021 stevensc 42
        ? allFeeds.map((feed, index) => {
4022 stevensc 43
          if (isMobile && isDashboard && index === 5) {
5106 stevensc 44
            const PeopleYouMayKnow = React.lazy(() => import('../../../shared/helpers/people-you-may-know/PeopleYouMayKnow'))
4021 stevensc 45
            return (
46
              <>
4062 stevensc 47
                <Suspense fallback={null}>
48
                  <PeopleYouMayKnow />
49
                </Suspense>
4021 stevensc 50
                <Feed
51
                  feed={feed}
52
                  key={feed.feed_unique}
53
                  owner_shared={feed.owner_shared}
54
                  image={image}
55
                />
56
              </>
57
            )
58
          }
4022 stevensc 59
          if (isMobile && isDashboard && index === 8) {
5106 stevensc 60
            const HomeNews = React.lazy(() => import('../home-section/HomeNews'))
4021 stevensc 61
            return (
62
              <>
4062 stevensc 63
                <Suspense fallback={null}>
64
                  <HomeNews />
65
                </Suspense>
4021 stevensc 66
                <Feed
67
                  feed={feed}
68
                  key={feed.feed_unique}
69
                  owner_shared={feed.owner_shared}
70
                  image={image}
71
                />
72
              </>
73
            )
74
          }
75
          return (
4017 stevensc 76
            <Feed
3993 stevensc 77
              feed={feed}
78
              key={feed.feed_unique}
79
              owner_shared={feed.owner_shared}
80
              image={image}
4017 stevensc 81
            />
4021 stevensc 82
          )
83
        })
5106 stevensc 84
        : <EmptySection message={LABELS.NOT_AVAILABLE_FEEDS} />
3993 stevensc 85
      }
4022 stevensc 86
      <Suspense fallback={null}>
4063 stevensc 87
        <ShareModal
88
          timelineUrl={timelineUrl}
89
          currentPage={currentPage}
90
        />
91
      </Suspense>
92
      <Suspense fallback={null}>
4022 stevensc 93
        <PaginationComponent
94
          onChangePage={onChangePageHandler}
95
          pages={pages}
96
          isRow
97
          currentActivePage={currentPage}
98
        />
99
      </Suspense>
3993 stevensc 100
    </>
5106 stevensc 101
  )
102
}
3993 stevensc 103
 
5106 stevensc 104
export default React.memo(FeedSection)