Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3685 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3682 stevensc 1
import React, { useEffect } from 'react'
2
import { useParams } from 'react-router-dom'
3
import { useDispatch, useSelector } from 'react-redux'
4
 
5
import { useFetch } from '@hooks'
6
import { feedTypes } from '@store/feed/feed.types'
7
import {
8
  fetchFeeds,
9
  setCurrentPage,
10
  setTimelineUrl
11
} from '@store/feed/feed.actions'
12
 
13
import Spinner from '@components/UI/Spinner'
14
import AppGrid from '@components/UI/layout/AppGrid'
15
import GroupWidget from '@components/widgets/linkedin/group-widget'
16
import GroupActions from '@components/group/group-actions/GroupActions'
17
import AboutGroup from '@components/group/AboutGroup'
18
import ShareComponent from '@components/dashboard/linkedin/share/ShareComponent'
19
import FeedList from '@components/dashboard/linkedin/feed-list/FeedList'
20
import Pagination from '@components/common/Pagination'
21
import Members from '@components/group/members/Members'
22
import ShareModal from '@components/modals/ShareModal'
23
 
24
const GroupPage = () => {
25
  const { uuid } = useParams()
26
  const dispatch = useDispatch()
27
  const { data, isLoading, refetch } = useFetch(`/group/view/${uuid}`)
28
 
29
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(
30
    ({ feed }) => feed
31
  )
32
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id])
33
 
34
  const onChangePageHandler = (currentPage) => {
35
    dispatch(setCurrentPage(currentPage))
36
    window.scrollTo(0, 0)
37
  }
38
 
39
  useEffect(() => {
40
    dispatch(fetchFeeds(timelineUrl, currentPage))
41
  }, [timelineUrl, currentPage])
42
 
43
  useEffect(() => {
44
    dispatch(setTimelineUrl(`/feed/timeline/${data.group_uuid}/group`))
45
  }, [data])
46
 
47
  if (isLoading) {
48
    return <Spinner />
49
  }
50
 
51
  return (
52
    <>
53
      <AppGrid
54
        renderSidebar={() => <GroupWidget group={data} />}
55
        renderMain={() => (
56
          <>
57
            <GroupActions {...data} refetch={refetch} />
58
            {data.without_feeds ? (
59
              <AboutGroup {...data} />
60
            ) : (
61
              <>
62
                <ShareComponent
63
                  feedType={feedTypes.GROUP}
64
                  postUrl={`/feed/add/group/${uuid}`}
65
                  image={data?.image}
66
                />
67
                <FeedList feeds={allFeeds} loading={loading} />
68
                <Pagination
69
                  pages={pages}
70
                  page={currentPage}
71
                  onChange={onChangePageHandler}
72
                />
73
              </>
74
            )}
75
          </>
76
        )}
77
        renderAside={() => (
78
          <>
79
            <Members id={data.group_uuid} />
80
            {!data.without_feeds && <AboutGroup {...data} />}
81
          </>
82
        )}
83
      />
84
      <ShareModal timelineUrl={timelineUrl} currentPage={currentPage} />
85
    </>
86
  )
87
}
88
 
89
export default GroupPage