Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2402 Rev 2403
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useEffect, useState } from 'react'
2
import { useHistory, useParams } from 'react-router-dom'
2
import { useHistory, useParams } from 'react-router-dom'
3
import { useSelector } from 'react-redux'
3
import { useDispatch, useSelector } from 'react-redux'
4
import { Container, Grid } from '@mui/material'
4
import { Container, Grid } from '@mui/material'
5
import parse from 'html-react-parser'
5
import parse from 'html-react-parser'
Línea 6... Línea 6...
6
 
6
 
-
 
7
import { axios } from '@app/utils'
7
import { axios } from '@app/utils'
8
import { addNotification } from '@app/redux/notification/notification.actions'
Línea 8... Línea 9...
8
import useFetch from '@app/hooks/useFetch'
9
import useFetch from '@app/hooks/useFetch'
9
 
10
 
-
 
11
import Widget from '@app/components/UI/Widget'
Línea 10... Línea 12...
10
import Widget from '@app/components/UI/Widget'
12
import AuthNavbar from '@app/components/UI/auth-navbar'
11
import AuthNavbar from '@app/components/UI/auth-navbar'
13
import Button from '@app/components/UI/buttons/Buttons'
12
 
14
 
13
function ShorterPostPage() {
-
 
-
 
15
function ShorterPostPage() {
14
  const { id } = useParams()
16
  const { id } = useParams()
-
 
17
  const history = useHistory()
15
  const history = useHistory()
18
 
Línea -... Línea 19...
-
 
19
  const [post, setPost] = useState({})
-
 
20
  const dispatch = useDispatch()
16
  const { data } = useFetch(`/shorter/${id}`, null)
21
  const { isAuth } = useSelector((state) => state.auth)
17
  const [post, setPost] = useState({})
22
 
18
  const { isAuth } = useSelector((state) => state.auth)
23
  const { data } = useFetch(`/shorter/${id}`, null)
Línea -... Línea 24...
-
 
24
 
-
 
25
  const getPost = async (url) => {
19
 
26
    return await axios.get(url).then((res) => res.data.data)
20
  const getPost = async (url) => {
27
  }
21
    return await axios.get(url).then((res) => res.data.data)
28
 
22
  }
29
  const handleClick = () => history.replace('/signin')
23
 
30
 
24
  useEffect(() => {
31
  useEffect(() => {
25
    if (!data) return
32
    if (!data) return
Línea 26... Línea 33...
26
    if (data?.redirect) {
33
    if (data?.redirect) {
27
      const redirectUrl = data?.url.split('.com')[1]
34
      const redirectUrl = data?.url.split('.com')[1]
-
 
35
      history.replace(redirectUrl)
28
      history.replace(redirectUrl)
36
      return
-
 
37
    }
-
 
38
 
-
 
39
    getPost(data?.url)
-
 
40
      .then((post) => setPost(post))
-
 
41
      .catch((error) => {
-
 
42
        console.log(error)
-
 
43
        dispatch(
29
      return
44
          addNotification({
Línea 30... Línea 45...
30
    }
45
            style: 'danger',
31
 
46
            msg: 'Ha ocurrido un error al obtener la información del post. Por favor, intentelo nuevamente.'
32
    getPost(data?.url)
47
          })
Línea 48... Línea 63...
48
        >
63
        >
49
          <Grid item xs={12} md={8}>
64
          <Grid item xs={12} md={8}>
50
            <Widget>
65
            <Widget>
51
              <Widget.Media alt={post.title} src={post.image} height={450} />
66
              <Widget.Media alt={post.title} src={post.image} height={450} />
Línea -... Línea 67...
-
 
67
 
52
 
68
              <Widget.Body>
-
 
69
                {parse(post.description ?? '')}
-
 
70
                <p>
-
 
71
                  Inicie sesion para visualizar los detalles de la publicación.
-
 
72
                </p>
-
 
73
                <Button onClick={handleClick}>Iniciar Sesion</Button>
53
              <Widget.Body>{parse(post.description ?? '')}</Widget.Body>
74
              </Widget.Body>
54
            </Widget>
75
            </Widget>
55
          </Grid>
76
          </Grid>
56
        </Grid>
77
        </Grid>
57
      </Container>
78
      </Container>