Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
6618 stevensc 1
import React, { Suspense, useEffect } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
3
import { fetchFeeds, setCurrentPage } from '../../redux/feed/feed.actions'
4
 
5
import EmptySection from '../UI/EmptySection'
6
import Spinner from '../UI/Spinner'
7
import Feed from '../feed/Feed'
8
 
9
const PaginationComponent = React.lazy(() =>
10
  import('../UI/PaginationComponent')
11
)
12
 
13
const isDashboard = window.location.pathname.includes('dashboard')
14
const isMobile = window.innerWidth < 768
15
 
16
const FeedSection = ({ feed, image }) => {
17
  const { allFeeds, timelineUrl, pages, currentPage, loading } = useSelector(
6621 stevensc 18
    ({ feed }) => feed
6618 stevensc 19
  )
6621 stevensc 20
  const labels = useSelector(({ intl }) => intl.labels)
6618 stevensc 21
  const dispatch = useDispatch()
22
 
6622 stevensc 23
  const fetchSpecificFeed = () => {
6618 stevensc 24
    dispatch(fetchFeeds(timelineUrl + '/feed/' + feed, 1))
6622 stevensc 25
  }
6618 stevensc 26
 
27
  useEffect(() => {
28
    if (feed) {
29
      return fetchSpecificFeed()
30
    } else {
31
      return dispatch(fetchFeeds(timelineUrl, currentPage))
32
    }
33
  }, [timelineUrl, currentPage, feed])
34
 
35
  const onChangePageHandler = (currentPage) => {
36
    dispatch(setCurrentPage(currentPage))
37
    dispatch(fetchFeeds(timelineUrl, currentPage))
38
    window.scrollTo(0, 0)
39
  }
40
 
41
  if (loading) {
42
    return <Spinner />
43
  }
44
 
45
  return (
46
    <>
47
      {allFeeds.length ? (
48
        allFeeds.map((feed, index) => {
49
          if (isMobile && isDashboard && index === 5) {
50
            const PeopleYouMayKnow = React.lazy(() =>
51
              import('../widgets/default/PeopleYouMayKnow')
52
            )
53
            return (
54
              <>
55
                <Suspense fallback={null}>
56
                  <PeopleYouMayKnow />
57
                </Suspense>
58
                <Feed
59
                  feed={feed}
60
                  key={feed.feed_unique}
61
                  owner_shared={feed.owner_shared}
62
                  image={image}
63
                />
64
              </>
65
            )
66
          }
67
          if (isMobile && isDashboard && index === 8) {
68
            const HomeNews = React.lazy(() =>
69
              import('../widgets/default/HomeNews')
70
            )
71
 
72
            return (
73
              <>
74
                <Suspense fallback={null}>
75
                  <HomeNews />
76
                </Suspense>
77
                <Feed
78
                  feed={feed}
79
                  key={feed.feed_unique}
80
                  owner_shared={feed.owner_shared}
81
                  image={image}
82
                />
83
              </>
84
            )
85
          }
86
          return (
87
            <Feed
88
              feed={feed}
89
              key={feed.feed_unique}
90
              owner_shared={feed.owner_shared}
91
              image={image}
92
            />
93
          )
94
        })
95
      ) : (
6619 stevensc 96
        <EmptySection message={labels.not_available_feeds} />
6618 stevensc 97
      )}
98
      <Suspense fallback={null}>
99
        <PaginationComponent
100
          onChangePage={onChangePageHandler}
101
          pages={pages}
102
          isRow
103
          currentActivePage={currentPage}
104
        />
105
      </Suspense>
106
    </>
107
  )
108
}
109
 
110
export default React.memo(FeedSection)