3719 |
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 { fetchFeeds, setCurrentPage, setTimelineUrl } from '@store/feed/feed.actions';
|
|
|
8 |
import { Pagination, Spinner } from '@shared/components';
|
|
|
9 |
import AppGrid from '@components/UI/layout/AppGrid';
|
|
|
10 |
import GroupWidget from '@components/widgets/linkedin/group-widget';
|
|
|
11 |
import GroupActions from '@groups/components/sections-cards/group-actions/GroupActions';
|
|
|
12 |
import ShareComponent from '@components/dashboard/linkedin/share/ShareComponent';
|
|
|
13 |
import FeedList from '@components/dashboard/linkedin/feed-list/FeedList';
|
|
|
14 |
import Members from '@groups/components/sections-cards/members/Members';
|
|
|
15 |
import AboutGroup from '@groups/components/AboutGroup';
|
|
|
16 |
|
|
|
17 |
const GroupPage = () => {
|
|
|
18 |
const { uuid } = useParams();
|
|
|
19 |
const dispatch = useDispatch();
|
|
|
20 |
const { data, isLoading, refetch } = useFetch(`/group/view/${uuid}`);
|
|
|
21 |
|
|
|
22 |
const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(({ feed }) => feed);
|
|
|
23 |
const allFeeds = feeds.allIds.map((id) => feeds.byId[id]);
|
|
|
24 |
|
|
|
25 |
const onChangePageHandler = (currentPage) => {
|
|
|
26 |
dispatch(setCurrentPage(currentPage));
|
|
|
27 |
window.scrollTo(0, 0);
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
useEffect(() => {
|
|
|
31 |
dispatch(fetchFeeds(timelineUrl, currentPage));
|
|
|
32 |
}, [timelineUrl, currentPage]);
|
|
|
33 |
|
|
|
34 |
useEffect(() => {
|
|
|
35 |
dispatch(setTimelineUrl(`/feed/timeline/${data.group_uuid}/group`));
|
|
|
36 |
}, [data]);
|
|
|
37 |
|
|
|
38 |
if (isLoading) {
|
|
|
39 |
return <Spinner />;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
return (
|
|
|
43 |
<AppGrid
|
|
|
44 |
renderSidebar={() => <GroupWidget group={data} />}
|
|
|
45 |
renderMain={() => (
|
|
|
46 |
<>
|
|
|
47 |
<GroupActions {...data} refetch={refetch} />
|
|
|
48 |
{data.without_feeds ? (
|
|
|
49 |
<AboutGroup {...data} />
|
|
|
50 |
) : (
|
|
|
51 |
<>
|
|
|
52 |
<ShareComponent
|
|
|
53 |
feedType={feedTypes.GROUP}
|
|
|
54 |
postUrl={`/feed/add/group/${uuid}`}
|
|
|
55 |
image={data?.image}
|
|
|
56 |
/>
|
|
|
57 |
<FeedList feeds={allFeeds} loading={loading} />
|
|
|
58 |
<Pagination pages={pages} page={currentPage} onChange={onChangePageHandler} />
|
|
|
59 |
</>
|
|
|
60 |
)}
|
|
|
61 |
</>
|
|
|
62 |
)}
|
|
|
63 |
renderAside={() => (
|
|
|
64 |
<>
|
|
|
65 |
<Members id={data.group_uuid} />
|
|
|
66 |
{!data.without_feeds && <AboutGroup {...data} />}
|
|
|
67 |
</>
|
|
|
68 |
)}
|
|
|
69 |
/>
|
|
|
70 |
);
|
|
|
71 |
};
|
|
|
72 |
|
|
|
73 |
export default GroupPage;
|