Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4820 | Rev 5118 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3361 stevensc 1
/* eslint-disable react/prop-types */
4821 stevensc 2
import React, { useEffect, useState } from 'react'
4817 stevensc 3
import { axios } from '../../utils'
4
import { addNotification } from '../../redux/notification/notification.actions'
4816 stevensc 5
import parse from 'html-react-parser'
6
 
7
// Components
4817 stevensc 8
import HomeNews from '../components/home-section/HomeNews'
9
import InputOption from '../templates/linkedin/Feed/InputOption'
10
import withExternalShare from '../templates/linkedin/Feed/withExternalShare'
3361 stevensc 11
 
4816 stevensc 12
// Icons
13
import ThumbUpAltOutlinedIcon from '@mui/icons-material/ThumbUpAltOutlined'
14
import ThumbUpAltIcon from '@mui/icons-material/ThumbUpAlt'
15
import ChatOutlinedIcon from '@mui/icons-material/ChatOutlined'
16
import SendOutlinedIcon from '@mui/icons-material/SendOutlined'
4817 stevensc 17
import AccessTimeIcon from '@mui/icons-material/AccessTime'
3361 stevensc 18
 
4817 stevensc 19
// Styles
20
import '../templates/linkedin/Feed/Feed.scss'
4818 stevensc 21
import FeedCommentSection from '../components/feed/feed-comment/FeedCommentSection'
4817 stevensc 22
 
4816 stevensc 23
export default function PostView({ post = {
24
    url: "",
25
    file: "imagengrupo.png",
26
    comments_url: "/post/344ccca7-6260-4564-93cc-85ed7682bec2/comments",
27
    comments_add_url: "/post/344ccca7-6260-4564-93cc-85ed7682bec2/comments/add"
28
}
29
}) {
30
    const [isLiked, setIsLiked] = useState(post.is_liked)
31
    const [externalShare, setExternalShare] = useState(post.total_share_external)
4818 stevensc 32
    const [comments, setComments] = useState([])
4816 stevensc 33
    const [isReadMoreActive, setIsReadMoreActive] = useState(false)
34
    const [showComments, setShowComments] = useState(false)
3810 stevensc 35
 
4816 stevensc 36
    const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
37
 
38
    const displayCommentSection = () => {
4819 stevensc 39
        setShowComments(!showComments)
4821 stevensc 40
    }
41
 
42
    const getComments = async () => {
43
        await axios.get(post.comments_url)
4818 stevensc 44
            .then(({ data: response }) => {
45
                if (!response.success) {
46
                    addNotification({ style: 'danger', msg: response.data })
47
                    return
48
                }
49
 
50
                setComments(response.data)
51
            })
4816 stevensc 52
    }
53
 
54
    const ExternalShareButton = withExternalShare(InputOption, post.share_external_url, {
55
        Icon: SendOutlinedIcon,
56
        color: 'gray',
4819 stevensc 57
        title: 'Enviar',
4816 stevensc 58
        shareUrl: post.share_increment_external_counter_url,
59
        setValue: handleExternalShare
60
    })
61
 
62
    const handleExternalShare = (value) => setExternalShare(value)
63
 
64
    const handleLike = (url) => {
65
        axios.post(url)
66
            .then(({ data: response }) => {
67
                if (!response.success) {
68
                    addNotification({ style: "danger", msg: response.data })
69
                    return
3810 stevensc 70
                }
4817 stevensc 71
                setIsLiked(!isLiked)
72
            })
4816 stevensc 73
    }
3810 stevensc 74
 
4816 stevensc 75
    const htmlParsedText = (fullStringText) => {
76
        const fullText = parse(fullStringText)
77
        if (fullStringText.length > 500) {
4817 stevensc 78
            const shortenedString = fullStringText.substr(0, 500)
79
            const shortenedText = parse(`${shortenedString}... `)
4816 stevensc 80
            return (
81
                <>
82
                    {isReadMoreActive ? fullText : shortenedText}
83
                    <span className='cursor-pointer' onClick={readMoreHandler}>
84
                        {isReadMoreActive ? " Leer menos" : " Leer más"}
85
                    </span>
86
                </>
4817 stevensc 87
            )
4816 stevensc 88
        }
89
        return <p>{fullText}</p>
90
    }
3361 stevensc 91
 
4821 stevensc 92
    useEffect(() => {
93
        if (showComments && !comments.length) getComments()
94
    }, [showComments])
95
 
1 www 96
    return (
3760 stevensc 97
        <div className="container">
4096 stevensc 98
            <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
4816 stevensc 99
                <div className="col-12 col-md-8 p-0">
100
                    <div className='feed'>
101
                        <div className='feed__body'>
102
                            {post.image && <img src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`} className="Entradas" loading='lazy' />}
103
                        </div>
104
                        <div className='feed__body'>
105
                            <div className='feed__header'>
106
                                <div className='feed__info'>
107
                                    <h2>{post.title}</h2>
108
                                    <div className='time__elapse'>
109
                                        <p>{post.addedOn}</p>
110
                                        <AccessTimeIcon className='time__elapse-icon' />
4093 stevensc 111
                                    </div>
4816 stevensc 112
                                </div>
3761 stevensc 113
                            </div>
4816 stevensc 114
                            {post.description && htmlParsedText(post.description)}
3761 stevensc 115
                        </div>
4819 stevensc 116
                        <div className="px-3 d-flex align-items-center justify-content-end" style={{ gap: '5px' }}>
4818 stevensc 117
                            {!!externalShare && <span>{`${externalShare} enviados`}</span>}
4093 stevensc 118
                        </div>
4818 stevensc 119
                        <div className='feed__buttons'>
120
                            <InputOption
121
                                Icon={isLiked ? ThumbUpAltIcon : ThumbUpAltOutlinedIcon}
4819 stevensc 122
                                title={isLiked ? 'Ya no me gusta' : 'Me gusta'}
4818 stevensc 123
                                color={isLiked ? '#7405f9' : 'gray'}
124
                                onClick={() => handleLike(isLiked ? post.unlike_url : post.like_url)}
125
                            />
126
                            <InputOption
127
                                Icon={ChatOutlinedIcon}
4819 stevensc 128
                                title='Comentarios'
4818 stevensc 129
                                color='gray'
130
                                onClick={displayCommentSection}
131
                            />
132
                            <ExternalShareButton />
133
                        </div>
134
                        <div className='px-2 pb-2'>
135
                            <FeedCommentSection
136
                                feedId={post.uuid}
137
                                addUrl={post.comments_add_url}
138
                                comments={comments}
139
                                isShow={showComments}
140
                            />
141
                        </div>
3760 stevensc 142
                    </div>
1 www 143
                </div>
4098 stevensc 144
                <div className="col-12 col-md-4 p-0">
145
                    <HomeNews currentPost={post.uuid} />
4093 stevensc 146
                </div>
147
            </div>
148
        </div >
1 www 149
    )
150
}