Rev 863 | Rev 890 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useEffect, useState } from 'react'import { Link } from 'react-router-dom'import { axios } from '../../../utils'import { useSelector } from 'react-redux'import { addNotification } from '../../../redux/notification/notification.actions'import styled from 'styled-components'import StyledContainer from '../WidgetLayout'import EmptySection from '../../UI/EmptySection'const StyledNewsList = styled.ul`display: flex;flex-direction: column;gap: 0.5rem;max-height: 380px;padding-bottom: 10px;overflow: auto;`const StyledNewItem = styled.div`display: flex;gap: 0.5rem;img {width: 100px;aspect-ratio: 3/2;object-fit: cover;}.post-info {display: flex;flex-direction: column;h4 {font-weight: 600;font-size: 1.2rem;color: subtitle-color;}span {color: $font-color;font-size: 0.8rem;}}`export default function HomeNews({ currentPost }) {const labels = useSelector(({ intl }) => intl.labels)const [news, setNews] = useState([])const loadNews = () => {axios.get('/helpers/posts').then(({ data: responseData }) => {const { data, success } = responseDataif (!success) {throw new Error(data)}setNews(data)}).catch(() => {addNotification({style: 'danger',msg: 'Disculpe, ha ocurrido un error buscando novedades'})})}useEffect(() => {loadNews()}, [])return (<StyledContainer><StyledContainer.Header title={labels.posts} /><StyledContainer.Body className='py-0'><StyledNewsList>{!news.length ? (<EmptySection message={labels.not_available_posts} />) : (news.map(({ link, title, image, date }) => {if (link.includes(currentPost)) return nullreturn (<StyledNewItem key={title}><Link to={link}><img src={image} alt={`${title} image`} /></Link><div className='post-info'><Link to={link}><h4 title={title}>{title}</h4></Link><span>{date}</span></div></StyledNewItem>)}))}</StyledNewsList></StyledContainer.Body></StyledContainer>)}