Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2280 | Rev 2780 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from 'react'
import { useNavigate } from 'react-router-dom'
import { useSelector } from 'react-redux'

import useFetch from '@app/hooks/useFetch'

import Widget from '@app/components/UI/Widget'
import List from '@app/components/UI/List'
import EmptySection from '@app/components/UI/EmptySection'

export default function HomeNews({ currentPost }) {
  const { data: news } = useFetch('/helpers/posts', [])
  const labels = useSelector(({ intl }) => intl.labels)
  const navigate = useNavigate()

  return (
    <Widget>
      <Widget.Header title={labels.posts} />

      <Widget.Body>
        {news?.length <= 0 ? (
          <EmptySection message={labels.not_available_posts} />
        ) : null}

        <List styles={{ maxHeight: '380px', overflow: 'scroll' }}>
          {news?.map(({ link, title, image, date }) => {
            if (link.includes(currentPost)) return null

            return (
              <List.Item
                key={title}
                title={title}
                image={image}
                subheader={date}
                avatarVariant='square'
                onClick={() => navigate(link)}
              />
            )
          })}
        </List>
      </Widget.Body>
    </Widget>
  )
}