Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3432 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3432 Rev 3719
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React, { useEffect } 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 { useFetch } from '@hooks'
5
import { useFetch } from '@hooks';
6
import {
-
 
7
  fetchFeeds,
-
 
8
  setCurrentPage,
-
 
9
  setTimelineUrl
-
 
10
} from '@store/feed/feed.actions'
6
import { fetchFeeds, setCurrentPage, setTimelineUrl } from '@store/feed/feed.actions';
11
 
7
 
12
import AppGrid from '@components/UI/layout/AppGrid'
8
import AppGrid from '@components/UI/layout/AppGrid';
13
import Spinner from '@components/UI/Spinner'
9
import Spinner from '@components/UI/Spinner';
14
import Pagination from '@components/common/Pagination'
10
import Pagination from '@components/common/Pagination';
15
import FeedList from '@components/dashboard/linkedin/feed-list/FeedList'
11
import FeedList from '@components/dashboard/linkedin/feed-list/FeedList';
16
import CompanyFollowers from '@components/company/company-followers'
12
import CompanyFollowers from '@components/company/company-followers';
17
import CompanyWidget from '@components/company/company-widget'
13
import CompanyWidget from '@components/company/company-widget';
18
import AboutCompany from '@components/company/about-company'
14
import AboutCompany from '@components/company/about-company';
19
import CompanyInfo from '@components/company/company-info'
15
import CompanyInfo from '@components/company/company-info';
20
 
16
 
21
export default function LinkedInCompany() {
17
export default function LinkedInCompany() {
22
  const { uuid } = useParams()
18
  const { uuid } = useParams();
23
  const dispatch = useDispatch()
19
  const dispatch = useDispatch();
24
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(
20
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(({ feed }) => feed);
25
    ({ feed }) => feed
-
 
26
  )
-
 
27
 
21
 
28
  const { data, isLoading, refetch } = useFetch(`/company/view/${uuid}`)
22
  const { data, isLoading, refetch } = useFetch(`/company/view/${uuid}`);
29
 
23
 
30
  const isFollower = !!data.link_unfollow
24
  const isFollower = !!data.link_unfollow;
31
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id])
25
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id]);
32
 
26
 
33
  const onChangePageHandler = (currentPage) => {
27
  const onChangePageHandler = (currentPage) => {
34
    dispatch(setCurrentPage(currentPage))
28
    dispatch(setCurrentPage(currentPage));
35
    window.scrollTo(0, 0)
29
    window.scrollTo(0, 0);
36
  }
30
  };
37
 
31
 
38
  useEffect(() => {
32
  useEffect(() => {
39
    dispatch(fetchFeeds(timelineUrl, currentPage))
33
    dispatch(fetchFeeds(timelineUrl, currentPage));
40
  }, [timelineUrl, currentPage])
34
  }, [timelineUrl, currentPage]);
41
 
35
 
42
  useEffect(() => {
36
  useEffect(() => {
43
    dispatch(setTimelineUrl(data.link_timeline))
37
    dispatch(setTimelineUrl(data.link_timeline));
44
  }, [data])
38
  }, [data]);
45
 
39
 
46
  if (isLoading) {
40
  if (isLoading) {
47
    return <Spinner />
41
    return <Spinner />;
48
  }
42
  }
49
 
43
 
50
  return (
44
  return (
51
    <AppGrid
45
    <AppGrid
52
      renderSidebar={() => <CompanyInfo company={data} />}
46
      renderSidebar={() => <CompanyInfo company={data} />}
53
      renderMain={() => (
47
      renderMain={() => (
54
        <>
48
        <>
55
          <CompanyWidget company={data} refetch={refetch} />
49
          <CompanyWidget company={data} refetch={refetch} />
56
          {loading && <Spinner />}
50
          {loading && <Spinner />}
57
          {!isFollower && <AboutCompany company={data} />}
51
          {!isFollower && <AboutCompany company={data} />}
58
          {isFollower && !loading && (
52
          {isFollower && !loading && (
59
            <>
53
            <>
60
              <FeedList feeds={allFeeds} />
54
              <FeedList feeds={allFeeds} />
61
              <Pagination
-
 
62
                pages={pages}
-
 
63
                page={currentPage}
-
 
64
                onChange={onChangePageHandler}
55
              <Pagination pages={pages} page={currentPage} onChange={onChangePageHandler} />
65
              />
-
 
66
            </>
56
            </>
67
          )}
57
          )}
68
        </>
58
        </>
69
      )}
59
      )}
70
      renderAside={() => (
60
      renderAside={() => (
71
        <>
61
        <>
72
          <CompanyFollowers companyId={uuid} />
62
          <CompanyFollowers companyId={uuid} />
73
          <AboutCompany company={data} />
63
          <AboutCompany company={data} />
74
        </>
64
        </>
75
      )}
65
      )}
76
    />
66
    />
77
  )
67
  );
78
}
68
}