Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3063 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3063 Rev 3585
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useEffect, useState } from 'react';
2
import { useDispatch, useSelector } from 'react-redux'
2
import { useDispatch, useSelector } from 'react-redux';
3
import { useParams } from 'react-router-dom'
3
import { useParams } from 'react-router-dom';
4
 
4
 
5
import {
-
 
6
  fetchFeeds,
-
 
7
  setCurrentPage,
-
 
8
  setTimelineUrl
-
 
9
} from '../../redux/feed/feed.actions'
5
import { fetchFeeds, setCurrentPage, setTimelineUrl } from '../../redux/feed/feed.actions';
10
import { getBackendVars } from '../../services/backendVars'
6
import { getBackendVars } from '../../services/backendVars';
11
 
7
 
12
import AppGrid from '@app/components/UI/layout/AppGrid'
8
import AppGrid from '@app/components/UI/layout/AppGrid';
13
import AboutCompany from '@app/components/company/AboutCompany'
9
import AboutCompany from '@app/components/company/AboutCompany';
14
import CompanyActions from '@app/components/company/CompanyActions'
10
import CompanyActions from '@app/components/company/CompanyActions';
15
import CompanyFollowers from '@app/components/company/CompanyFollowers'
11
import CompanyFollowers from '@app/components/company/CompanyFollowers';
16
import FeedList from '@app/components/dashboard/linkedin/feed-list/FeedList'
12
import FeedList from '@app/components/dashboard/linkedin/feed-list/FeedList';
17
import GroupInfo from '@app/components/widgets/linkedin/group-widget'
13
import GroupInfo from '@app/components/widgets/linkedin/group-widget';
18
import Pagination from '@components/common/Pagination'
14
import Pagination from '@components/common/Pagination';
19
 
-
 
20
import './styles/linkedin.scss'
-
 
Línea 21... Línea 15...
21
 
15
 
22
const LinkedInCompany = () => {
16
const LinkedInCompany = () => {
23
  const [backendVars, setBackendVars] = useState(null)
17
  const [backendVars, setBackendVars] = useState(null);
24
  const [actionsUrls, setActionsUrls] = useState({})
18
  const [actionsUrls, setActionsUrls] = useState({});
25
  const [isFollower, setIsFollower] = useState(false)
19
  const [isFollower, setIsFollower] = useState(false);
26
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(
-
 
27
    ({ feed }) => feed
-
 
28
  )
20
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(({ feed }) => feed);
29
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id])
21
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id]);
30
  const { uuid } = useParams()
22
  const { uuid } = useParams();
Línea 31... Línea 23...
31
  const dispatch = useDispatch()
23
  const dispatch = useDispatch();
32
 
24
 
33
  const getCompanyVars = () => {
25
  const getCompanyVars = () => {
Línea 34... Línea 26...
34
    getBackendVars(`/company/view/${uuid}`).then((vars) => {
26
    getBackendVars(`/company/view/${uuid}`).then((vars) => {
35
      const actions = {}
27
      const actions = {};
36
 
28
 
37
      Object.entries(vars).forEach(([key, value]) => {
29
      Object.entries(vars).forEach(([key, value]) => {
38
        if (!key.includes('link')) return
30
        if (!key.includes('link')) return;
39
        actions[key] = value
31
        actions[key] = value;
40
      })
32
      });
41
 
33
 
42
      setActionsUrls(actions)
34
      setActionsUrls(actions);
43
      dispatch(setTimelineUrl(vars.link_timeline))
35
      dispatch(setTimelineUrl(vars.link_timeline));
44
      setIsFollower(!!vars.link_unfollow)
36
      setIsFollower(!!vars.link_unfollow);
Línea 45... Línea 37...
45
      setBackendVars(vars)
37
      setBackendVars(vars);
46
    })
38
    });
47
  }
39
  };
48
 
40
 
Línea 49... Línea 41...
49
  const onChangePageHandler = (currentPage) => {
41
  const onChangePageHandler = (currentPage) => {
50
    dispatch(setCurrentPage(currentPage))
42
    dispatch(setCurrentPage(currentPage));
51
    window.scrollTo(0, 0)
43
    window.scrollTo(0, 0);
Línea 52... Línea 44...
52
  }
44
  };
53
 
45
 
54
  useEffect(() => {
46
  useEffect(() => {
Línea 55... Línea 47...
55
    dispatch(fetchFeeds(timelineUrl, currentPage))
47
    dispatch(fetchFeeds(timelineUrl, currentPage));
56
  }, [timelineUrl, currentPage])
48
  }, [timelineUrl, currentPage]);
57
 
49
 
58
  useEffect(() => {
50
  useEffect(() => {
Línea 84... Línea 76...
84
            refetch={getCompanyVars}
76
            refetch={getCompanyVars}
85
            actionLinks={actionsUrls}
77
            actionLinks={actionsUrls}
86
          />
78
          />
87
          {!isFollower ? <AboutCompany {...backendVars} /> : null}
79
          {!isFollower ? <AboutCompany {...backendVars} /> : null}
88
          {isFollower && !loading ? <FeedList feeds={allFeeds} /> : null}
80
          {isFollower && !loading ? <FeedList feeds={allFeeds} /> : null}
89
          <Pagination
-
 
90
            pages={pages}
-
 
91
            page={currentPage}
-
 
92
            onChange={onChangePageHandler}
81
          <Pagination pages={pages} page={currentPage} onChange={onChangePageHandler} />
93
          />
-
 
94
        </>
82
        </>
95
      )}
83
      )}
96
      renderAside={() => (
84
      renderAside={() => (
97
        <>
85
        <>
98
          <CompanyFollowers companyId={uuid} />
86
          <CompanyFollowers companyId={uuid} />
99
          <AboutCompany {...backendVars} />
87
          <AboutCompany {...backendVars} />
100
        </>
88
        </>
101
      )}
89
      )}
102
    />
90
    />
103
  )
91
  );
104
}
92
};
Línea 105... Línea 93...
105
 
93