Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3481 Rev 3505
Línea 1... Línea 1...
1
import React, { useCallback, useEffect, useRef, useState } from 'react';
1
import React, { useCallback, useEffect, useRef, useState } from 'react';
2
import { axios } from '../../../utils';
-
 
-
 
2
 
3
import { useSelector } from 'react-redux';
3
import { useSelector } from 'react-redux';
4
import { Box, Typography } from '@mui/material';
4
import { Box, Typography } from '@mui/material';
Línea 5... Línea 5...
5
 
5
 
-
 
6
import { useNearScreen, useMicroLearning } from '@hooks';
-
 
7
import { api } from '@shared/libs';
-
 
8
import { List, Spinner } from '@shared/components';
Línea 6... Línea -...
6
import { useNearScreen, useMicroLearning } from '@hooks';
-
 
7
 
-
 
8
import Spinner from 'components/UI/Spinner';
-
 
9
import EmptySection from 'components/UI/EmptySection';
-
 
10
import DetailTag from 'components/micro-learning/DetailTag';
9
import DetailTag from '@microlearning/components/DetailTag';
11
 
10
 
12
const TimelinePage = () => {
11
export function TimelinePage() {
13
  const { link_timeline: linkTimeline } = useMicroLearning();
12
  const { link_timeline: linkTimeline } = useMicroLearning();
14
  const [items, setItems] = useState([]);
13
  const [items, setItems] = useState([]);
15
  const [isLoading, setIsLoading] = useState(false);
14
  const [isLoading, setIsLoading] = useState(false);
Línea 26... Línea 25...
26
    (url = '') => {
25
    (url = '') => {
27
      if (isLoading || !url) return;
26
      if (isLoading || !url) return;
Línea 28... Línea 27...
28
 
27
 
Línea 29... Línea 28...
29
      setIsLoading(true);
28
      setIsLoading(true);
30
 
29
 
31
      axios
30
      api
32
        .get(`${url}?page=${currentPage}`)
-
 
33
        .then((response) => {
-
 
34
          const { data, success } = response.data;
-
 
35
 
-
 
36
          if (!success) {
-
 
37
            throw new Error(data);
-
 
38
          }
31
        .get(`${url}?page=${currentPage}`)
39
 
32
        .then((data) => {
40
          setCurrentPage((prevCurrentPage) => prevCurrentPage + 1);
33
          setCurrentPage((prevCurrentPage) => prevCurrentPage + 1);
41
          setTotalPages(data.total.pages);
34
          setTotalPages(data.total.pages);
42
          setItems((prevItems) => [...prevItems, ...data.current.items]);
35
          setItems((prevItems) => [...prevItems, ...data.current.items]);
Línea 53... Línea 46...
53
 
46
 
54
  useEffect(() => {
47
  useEffect(() => {
55
    const getData = (url = '') => {
48
    const getData = (url = '') => {
Línea 56... Línea 49...
56
      setIsLoading(true);
49
      setIsLoading(true);
57
 
50
 
58
      axios
51
      api
59
        .get(url)
52
        .get(url)
Línea 60... Línea 53...
60
        .then((response) => {
53
        .then((response) => {
Línea 91... Línea 84...
91
 
84
 
92
        <div ref={loaderRef}>{currentPage < totalPages ? <Spinner /> : null}</div>
85
        <div ref={loaderRef}>{currentPage < totalPages ? <Spinner /> : null}</div>
93
      </Box>
86
      </Box>
94
    </>
87
    </>
95
  );
88
  );
Línea 96... Línea 89...
96
};
89
}
97
 
90
 
Línea 98... Línea -...
98
const TimelineList = ({ items = [] }) => {
-
 
99
  const labels = useSelector(({ intl }) => intl.labels);
-
 
100
 
-
 
101
  if (!items.length) {
-
 
102
    return <EmptySection message={labels.datatable_szerorecords} />;
91
const TimelineList = ({ items = [] }) => {
103
  }
92
  const labels = useSelector(({ intl }) => intl.labels);
-
 
93
 
-
 
94
  return (
104
 
95
    <List
105
  return (
96
      items={items}
106
    <>
97
      emptyMessage={labels.datatable_szerorecords}
107
      {items.map(({ activity, added_on }, i) => (
98
      renderItem={({ activity, added_on }, i) => (
108
        <DetailTag key={i} title={activity} label={added_on} />
99
        <DetailTag key={i} title={activity} label={added_on} />
109
      ))}
100
      )}
110
    </>
-
 
111
  );
-