3736 |
stevensc |
1 |
import React, { useContext, useEffect } from 'react';
|
3719 |
stevensc |
2 |
import { useDispatch, useSelector } from 'react-redux';
|
3736 |
stevensc |
3 |
import { Grid } from '@mui/material';
|
3719 |
stevensc |
4 |
|
3736 |
stevensc |
5 |
// Global store
|
|
|
6 |
import { fetchFeeds, setCurrentPage, setTimelineUrl } from '@store/feed/feed.actions';
|
3719 |
stevensc |
7 |
import { feedTypes } from '@store/feed/feed.types';
|
3736 |
stevensc |
8 |
|
|
|
9 |
// Module context
|
|
|
10 |
import { EditGroupContext } from '@groups/contexts';
|
|
|
11 |
|
|
|
12 |
// Module components
|
3719 |
stevensc |
13 |
import { Pagination, Spinner } from '@shared/components';
|
3736 |
stevensc |
14 |
import { GroupCard, Members } from '@groups/components';
|
|
|
15 |
|
|
|
16 |
// Global components
|
3719 |
stevensc |
17 |
import GroupWidget from '@components/widgets/linkedin/group-widget';
|
3736 |
stevensc |
18 |
import AboutGroup from '@groups/components/AboutGroup';
|
3719 |
stevensc |
19 |
import ShareComponent from '@components/dashboard/linkedin/share/ShareComponent';
|
|
|
20 |
import FeedList from '@components/dashboard/linkedin/feed-list/FeedList';
|
|
|
21 |
|
|
|
22 |
const GroupPage = () => {
|
|
|
23 |
const dispatch = useDispatch();
|
|
|
24 |
|
3736 |
stevensc |
25 |
const { group, loading } = useContext(EditGroupContext);
|
|
|
26 |
|
|
|
27 |
const { feeds, timelineUrl, currentPage, pages } = useSelector(({ feed }) => feed);
|
3719 |
stevensc |
28 |
const allFeeds = feeds.allIds.map((id) => feeds.byId[id]);
|
|
|
29 |
|
|
|
30 |
const onChangePageHandler = (currentPage) => {
|
|
|
31 |
dispatch(setCurrentPage(currentPage));
|
|
|
32 |
window.scrollTo(0, 0);
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
useEffect(() => {
|
|
|
36 |
dispatch(fetchFeeds(timelineUrl, currentPage));
|
|
|
37 |
}, [timelineUrl, currentPage]);
|
|
|
38 |
|
|
|
39 |
useEffect(() => {
|
3736 |
stevensc |
40 |
if (group) {
|
|
|
41 |
dispatch(setTimelineUrl(`/feed/timeline/${group.group_uuid}/group`));
|
|
|
42 |
}
|
|
|
43 |
}, [group]);
|
3719 |
stevensc |
44 |
|
3736 |
stevensc |
45 |
if (loading || !group) return <Spinner />;
|
3719 |
stevensc |
46 |
|
|
|
47 |
return (
|
3736 |
stevensc |
48 |
<Grid container spacing={1}>
|
|
|
49 |
<Grid size={{ xs: 12, md: 3 }}>
|
|
|
50 |
<GroupWidget group={group} />
|
|
|
51 |
</Grid>
|
|
|
52 |
<Grid size={{ xs: 12, md: 6 }} sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
|
|
|
53 |
<GroupCard group={group} uuid={group.group_uuid} />
|
|
|
54 |
{group.without_feeds ? (
|
|
|
55 |
<AboutGroup {...group} />
|
|
|
56 |
) : (
|
|
|
57 |
<>
|
|
|
58 |
<ShareComponent
|
|
|
59 |
feedType={feedTypes.GROUP}
|
|
|
60 |
postUrl={`/feed/add/group/${group.group_uuid}`}
|
|
|
61 |
image={group.image}
|
|
|
62 |
/>
|
|
|
63 |
<FeedList feeds={allFeeds} loading={loading} />
|
|
|
64 |
<Pagination pages={pages} page={currentPage} onChange={onChangePageHandler} />
|
|
|
65 |
</>
|
|
|
66 |
)}
|
|
|
67 |
</Grid>
|
|
|
68 |
<Grid size={{ xs: 12, md: 3 }} sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
|
|
|
69 |
<Members uuid={group.group_uuid} />
|
|
|
70 |
{!group.without_feeds && <AboutGroup {...group} />}
|
|
|
71 |
</Grid>
|
|
|
72 |
</Grid>
|
3719 |
stevensc |
73 |
);
|
|
|
74 |
};
|
|
|
75 |
|
|
|
76 |
export default GroupPage;
|