Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5376 | Rev 5438 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3503 stevensc 1
/* eslint-disable react/prop-types */
5104 stevensc 2
import React, { useEffect, useState } from 'react'
3
import { addNotification } from '../../../redux/notification/notification.actions'
4
import EmptySection from '../../../shared/empty-section/EmptySection'
5
import { axios } from '../../../utils'
1386 steven 6
 
5104 stevensc 7
export default function HomeNews ({
8
  classname = 'peopleYouMayKnow',
9
  currentPost = null
3503 stevensc 10
}) {
5104 stevensc 11
  const [news, setNews] = useState([])
12
  const loadNews = () => {
13
    axios.get('/helpers/posts')
14
      .then(({ data: response }) => {
15
        if (!response.success) {
16
          addNotification({
17
            style: 'danger',
18
            msg: response.data
19
          })
20
        }
21
        setNews(response.data)
22
      })
23
      .catch(() => {
24
        addNotification({
25
          style: 'danger',
26
          msg: 'Disculpe, ha ocurrido un error buscando novedades'
27
        })
28
      })
29
  }
4098 stevensc 30
 
5104 stevensc 31
  useEffect(() => {
32
    loadNews()
33
  }, [])
4088 stevensc 34
 
5104 stevensc 35
  return (
5376 stevensc 36
    <div className={classname}>
37
      <div className="sd-title">
38
        <h3>{LABELS.POSTS}</h3>
39
      </div>
5377 stevensc 40
      <div className="posts-list">
5376 stevensc 41
        {!news.length
42
          ? <EmptySection message={LABELS.NOT_AVAILABLE_POSTS} />
43
          : news.map(element => {
44
            if (element.link.includes(currentPost)) {
45
              return null
46
            }
4098 stevensc 47
 
5376 stevensc 48
            return (
5377 stevensc 49
              <div key={element.title} className='post-item'>
5376 stevensc 50
                <img src={element.image} alt={`${element.title} image`} />
51
                <a href={element.link} target='secondary'>
52
                  <h4>{element.title}</h4>
53
                </a>
54
                <span>{element.date}</span>
55
                <a
56
                  className="btn btn-primary"
57
                  href={element.link}
58
                  target="secondary"
59
                >
60
                  {LABELS.VIEW_MORE}
61
                </a>
62
              </div>
63
            )
64
          })}
65
      </div>
66
    </div>
5104 stevensc 67
  )
1386 steven 68
}