Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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