Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5438 | Rev 5944 | 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'
5438 stevensc 6
import { useSelector } from 'react-redux'
1386 steven 7
 
5438 stevensc 8
export default function HomeNews ({ currentPost }) {
5104 stevensc 9
  const [news, setNews] = useState([])
5438 stevensc 10
  const labels = useSelector(state => state.labels)
11
 
5104 stevensc 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 (
5438 stevensc 36
    <div className='posts-widget'>
5440 stevensc 37
      <h3>{labels.POSTS}</h3>
5377 stevensc 38
      <div className="posts-list">
5376 stevensc 39
        {!news.length
5438 stevensc 40
          ? <EmptySection message={labels.NOT_AVAILABLE_POSTS} />
5376 stevensc 41
          : news.map(element => {
42
            if (element.link.includes(currentPost)) {
43
              return null
44
            }
4098 stevensc 45
 
5376 stevensc 46
            return (
5377 stevensc 47
              <div key={element.title} className='post-item'>
5376 stevensc 48
                <img src={element.image} alt={`${element.title} image`} />
49
                <a href={element.link} target='secondary'>
50
                  <h4>{element.title}</h4>
51
                </a>
52
                <span>{element.date}</span>
53
                <a
54
                  className="btn btn-primary"
55
                  href={element.link}
56
                  target="secondary"
57
                >
5438 stevensc 58
                  {labels.VIEW_MORE}
5376 stevensc 59
                </a>
60
              </div>
61
            )
62
          })}
63
      </div>
64
    </div>
5104 stevensc 65
  )
1386 steven 66
}