Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 1507 Rev 2277
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React from 'react'
2
import { Link } from 'react-router-dom'
2
import { Link } from 'react-router-dom'
3
import { axios } from '../../../utils'
-
 
4
import { useSelector } from 'react-redux'
3
import { useSelector } from 'react-redux'
5
import { addNotification } from '../../../redux/notification/notification.actions'
-
 
6
import styled from 'styled-components'
4
import styled from 'styled-components'
Línea -... Línea 5...
-
 
5
 
-
 
6
import useFetch from '@app/hooks/useFetch'
7
 
7
 
8
import WidgetWrapper from '../WidgetLayout'
8
import Widget from '@app/components/UI/Widget'
Línea 9... Línea 9...
9
import EmptySection from '../../UI/EmptySection'
9
import EmptySection from '@app/components/UI/EmptySection'
10
 
10
 
11
const StyledNewsList = styled.ul`
11
const StyledNewsList = styled.ul`
12
  display: flex;
12
  display: flex;
Línea 47... Línea 47...
47
    }
47
    }
48
  }
48
  }
49
`
49
`
Línea 50... Línea 50...
50
 
50
 
-
 
51
export default function HomeNews({ currentPost }) {
51
export default function HomeNews({ currentPost }) {
52
  const { data: news } = useFetch('/helpers/posts')
52
  const labels = useSelector(({ intl }) => intl.labels)
-
 
53
  const [news, setNews] = useState([])
-
 
54
 
-
 
55
  const loadNews = () => {
-
 
56
    axios
-
 
57
      .get('/helpers/posts')
-
 
58
      .then(({ data: responseData }) => {
-
 
59
        const { data, success } = responseData
-
 
60
 
-
 
61
        if (!success) {
-
 
62
          throw new Error(data)
-
 
63
        }
-
 
64
 
-
 
65
        setNews(data)
-
 
66
      })
-
 
67
      .catch(() => {
-
 
68
        addNotification({
-
 
69
          style: 'danger',
-
 
70
          msg: 'Disculpe, ha ocurrido un error buscando novedades'
-
 
71
        })
-
 
72
      })
-
 
73
  }
-
 
74
 
-
 
75
  useEffect(() => {
-
 
76
    loadNews()
-
 
Línea 77... Línea 53...
77
  }, [])
53
  const labels = useSelector(({ intl }) => intl.labels)
78
 
54
 
79
  return (
55
  return (
Línea 80... Línea 56...
80
    <WidgetWrapper>
56
    <Widget>
81
      <WidgetWrapper.Header title={labels.posts} />
57
      <Widget.Header title={labels.posts} />
82
 
58
 
83
      <WidgetWrapper.Body className='py-0'>
59
      <Widget.Body>
84
        <StyledNewsList>
60
        <StyledNewsList>
85
          {!news.length ? (
61
          {!news.length ? (
Línea 103... Línea 79...
103
                </StyledNewItem>
79
                </StyledNewItem>
104
              )
80
              )
105
            })
81
            })
106
          )}
82
          )}
107
        </StyledNewsList>
83
        </StyledNewsList>
108
      </WidgetWrapper.Body>
84
      </Widget.Body>
109
    </WidgetWrapper>
85
    </Widget>
110
  )
86
  )
111
}
87
}