Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 5 Rev 67
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useEffect, useState } from "react";
2
import { axios } from '../../../utils'
2
import { axios } from "../../../utils";
3
import { useSelector } from 'react-redux'
3
import { useSelector } from "react-redux";
Línea 4... Línea 4...
4
 
4
 
Línea 5... Línea 5...
5
import { addNotification } from '../../../redux/notification/notification.actions'
5
import { addNotification } from "../../../redux/notification/notification.actions";
6
 
6
 
Línea 7... Línea 7...
7
import EmptySection from '../../UI/EmptySection'
7
import EmptySection from "../../UI/EmptySection";
8
import { Link } from 'react-router-dom'
8
import { Link } from "react-router-dom";
9
 
9
 
Línea 10... Línea 10...
10
export default function HomeNews({ currentPost }) {
10
export default function HomeNews({ currentPost }) {
11
  const labels = useSelector(({ intl }) => intl.labels)
11
  const labels = useSelector(({ intl }) => intl.labels);
12
  const [news, setNews] = useState([])
12
  const [news, setNews] = useState([]);
13
 
13
 
-
 
14
  const loadNews = () => {
-
 
15
    axios
14
  const loadNews = () => {
16
      .get("/helpers/posts")
15
    axios
17
      .then(({ data: response }) => {
16
      .get('/helpers/posts')
18
        const { data, success } = response.data;
17
      .then(({ data: response }) => {
19
 
18
        if (!response.success) {
20
        if (!success) {
-
 
21
          addNotification({
19
          addNotification({
22
            style: "danger",
-
 
23
            msg: data,
20
            style: 'danger',
24
          });
21
            msg: response.data,
25
          return;
22
          })
26
        }
23
        }
27
 
24
        setNews(response.data)
28
        setNews(data);
25
      })
29
      })
26
      .catch(() => {
30
      .catch(() => {
27
        addNotification({
31
        addNotification({
28
          style: 'danger',
32
          style: "danger",
Línea 29... Línea 33...
29
          msg: 'Disculpe, ha ocurrido un error buscando novedades',
33
          msg: "Disculpe, ha ocurrido un error buscando novedades",
30
        })
34
        });
31
      })
35
      });
Línea 32... Línea 36...
32
  }
36
  };
33
 
37
 
34
  useEffect(() => {
38
  useEffect(() => {
35
    loadNews()
39
    loadNews();
36
  }, [])
40
  }, []);
37
 
41
 
38
  return (
42
  return (
39
    <div className="posts-widget">
43
    <div className="posts-widget">
40
      <h3>{labels.posts}</h3>
44
      <h3>{labels.posts}</h3>
41
      <div className="posts-list">
45
      <div className="posts-list">
42
        {!news.length ? (
46
        {!news.length ? (
Línea 43... Línea 47...
43
          <EmptySection message={labels.not_available_posts} />
47
          <EmptySection message={labels.not_available_posts} />
44
        ) : (
48
        ) : (
45
          news.map((element) => {
49
          news.map((element) => {
Línea 57... Línea 61...
57
                    <h4 title={element.title}>{element.title}</h4>
61
                    <h4 title={element.title}>{element.title}</h4>
58
                  </Link>
62
                  </Link>
59
                  <span>{element.date}</span>
63
                  <span>{element.date}</span>
60
                </div>
64
                </div>
61
              </div>
65
              </div>
62
            )
66
            );
63
          })
67
          })
64
        )}
68
        )}
65
      </div>
69
      </div>
66
    </div>
70
    </div>
67
  )
71
  );
68
}
72
}