Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 4824 Rev 5104
Línea 1... Línea 1...
1
/* eslint-disable react/prop-types */
1
/* eslint-disable react/prop-types */
2
import React, { useEffect, useState } from 'react';
2
import React, { useEffect, useState } from 'react'
3
import { addNotification } from '../../../redux/notification/notification.actions';
3
import { addNotification } from '../../../redux/notification/notification.actions'
4
import EmptySection from '../../../shared/empty-section/EmptySection';
4
import EmptySection from '../../../shared/empty-section/EmptySection'
5
import { axios } from '../../../utils';
5
import { axios } from '../../../utils'
Línea 6... Línea 6...
6
 
6
 
7
export default function HomeNews({
7
export default function HomeNews ({
8
    classname = 'peopleYouMayKnow',
8
  classname = 'peopleYouMayKnow',
9
    currentPost = null
9
  currentPost = null
10
}) {
10
}) {
11
    const [news, setNews] = useState([])
11
  const [news, setNews] = useState([])
12
    const loadNews = () => {
12
  const loadNews = () => {
13
        axios.get('/helpers/posts')
13
    axios.get('/helpers/posts')
14
            .then(({ data: response }) => {
14
      .then(({ data: response }) => {
15
                if (!response.success) {
15
        if (!response.success) {
16
                    addNotification({
16
          addNotification({
17
                        style: "danger",
17
            style: 'danger',
18
                        msg: response.data,
18
            msg: response.data
19
                    });
19
          })
20
                }
20
        }
21
                setNews(response.data)
21
        setNews(response.data)
22
            })
22
      })
23
            .catch(() => {
23
      .catch(() => {
24
                addNotification({
24
        addNotification({
25
                    style: "danger",
25
          style: 'danger',
26
                    msg: "Disculpe, ha ocurrido un error buscando novedades",
26
          msg: 'Disculpe, ha ocurrido un error buscando novedades'
27
                });
27
        })
28
            })
28
      })
Línea 29... Línea 29...
29
    }
29
  }
30
 
30
 
31
    useEffect(() => {
31
  useEffect(() => {
Línea 32... Línea 32...
32
        loadNews()
32
    loadNews()
33
    }, [])
33
  }, [])
34
 
34
 
35
    return (
35
  return (
36
        <div className={classname}>
36
        <div className={classname}>
37
            <div className="sd-title">
37
            <div className="sd-title">
38
                <h3>Novedades</h3>
38
                <h3>{LABELS.POSTS}</h3>
39
            </div>
39
            </div>
40
            <div className="suggestions-list">
40
            <div className="suggestions-list">
41
                {!news.length
41
                {!news.length
42
                    ? <EmptySection message='Aún no hay novedades disponibles' />
42
                  ? <EmptySection message={LABELS.NOT_AVAILABLE_POSTS} />
43
                    : news.map(element => {
43
                  : news.map(element => {
Línea 44... Línea 44...
44
                        if (element.link.includes(currentPost)) {
44
                    if (element.link.includes(currentPost)) {
45
                            return null
45
                      return null
46
                        }
46
                    }
47
 
47
 
48
                        return (
48
                    return (
49
                            <div key={element.title} className='postsList'>
49
                            <div key={element.title} className='postsList'>
Línea 57... Línea 57...
57
                                <a
57
                                <a
58
                                    className="btn btn-primary"
58
                                    className="btn btn-primary"
59
                                    href={element.link}
59
                                    href={element.link}
60
                                    target="secondary"
60
                                    target="secondary"
61
                                >
61
                                >
62
                                    Ver más
62
                                    {LABELS.VIEW_MORE}
63
                                </a>
63
                                </a>
64
                            </div>
64
                            </div>
65
                        )
65
                    )
66
                    })}
66
                  })}
67
            </div>
67
            </div>
68
        </div >
68
        </div>
69
    )
69
  )
70
}
70
}