Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2386 Rev 2388
Línea 1... Línea 1...
1
import React from 'react'
1
import React, { useEffect, useState } from 'react'
-
 
2
import { useHistory, useParams } from 'react-router-dom'
2
import { useSelector } from 'react-redux'
3
import { useSelector } from 'react-redux'
3
import { Container, Grid } from '@mui/material'
4
import { Container, Grid } from '@mui/material'
4
import parse from 'html-react-parser'
5
import parse from 'html-react-parser'
Línea 5... Línea 6...
5
 
6
 
Línea 6... Línea 7...
6
import useFetch from '@app/hooks/useFetch'
7
import useFetch from '@app/hooks/useFetch'
7
 
8
 
8
import Widget from '@app/components/UI/Widget'
9
import Widget from '@app/components/UI/Widget'
9
import SurveyForm from '@app/components/survey-form/SurveyForm'
10
import SurveyForm from '@app/components/survey-form/SurveyForm'
Línea 10... Línea 11...
10
import AuthNavbar from '@app/components/UI/auth-navbar'
11
import AuthNavbar from '@app/components/UI/auth-navbar'
11
import { useParams } from 'react-router-dom'
-
 
12
 
12
import { axios } from '@app/utils'
-
 
13
 
13
function ShorterPostPage() {
14
function ShorterPostPage() {
14
  const { isAuth } = useSelector((state) => state.auth)
15
  const { id } = useParams()
-
 
16
  const history = useHistory()
Línea -... Línea 17...
-
 
17
  const { data } = useFetch(`/shorter/${id}`, null)
-
 
18
  const [post, setPost] = useState({})
-
 
19
  const { isAuth } = useSelector((state) => state.auth)
-
 
20
 
-
 
21
  const getPost = async (url) => {
15
  const { id } = useParams()
22
    return await axios.get(url).then((res) => res.data)
-
 
23
  }
-
 
24
 
-
 
25
  useEffect(() => {
-
 
26
    if (data.redirect) return history.replace(data.url)
-
 
27
 
Línea 16... Línea 28...
16
  const { data } = useFetch(`/shorter/${id}`, null)
28
    getPost(data.url)
17
  const { data: post } = useFetch(data)
29
      .then((post) => setPost(post))
18
 
30
      .catch((error) => console.log(error))
19
  const { shared_image, shared_title, shared_description } = post
31
  }, [data])
Línea 30... Línea 42...
30
            alignItems: 'center'
42
            alignItems: 'center'
31
          }}
43
          }}
32
        >
44
        >
33
          <Grid item xs={12} md={8}>
45
          <Grid item xs={12} md={8}>
34
            <Widget>
46
            <Widget>
-
 
47
              <Widget.Header
35
              <Widget.Header avatar={shared_image} title={shared_title} />
48
                avatar={post.shared_image}
-
 
49
                title={post.shared_title}
-
 
50
              />
Línea 36... Línea 51...
36
 
51
 
37
              <Widget.Body>
52
              <Widget.Body>
38
                <FeedContent
53
                <FeedContent
39
                  type='description'
54
                  type='description'
40
                  content={{ owner_description: shared_description ?? '' }}
55
                  content={{ owner_description: post.shared_description ?? '' }}
41
                />
56
                />
42
              </Widget.Body>
57
              </Widget.Body>
43
            </Widget>
58
            </Widget>
44
          </Grid>
59
          </Grid>