Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4817 | Rev 4819 | 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 */
4818 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 = () => {
39
        axios.get(post.comments_url)
4818 stevensc 40
            .then(({ data: response }) => {
41
                if (!response.success) {
42
                    addNotification({ style: 'danger', msg: response.data })
43
                    return
44
                }
45
 
46
                setComments(response.data)
47
            })
4816 stevensc 48
    }
49
 
50
    const ExternalShareButton = withExternalShare(InputOption, post.share_external_url, {
51
        Icon: SendOutlinedIcon,
52
        color: 'gray',
53
        title: 'Send',
54
        shareUrl: post.share_increment_external_counter_url,
55
        setValue: handleExternalShare
56
    })
57
 
58
    const handleExternalShare = (value) => setExternalShare(value)
59
 
60
    const handleLike = (url) => {
61
        axios.post(url)
62
            .then(({ data: response }) => {
63
                if (!response.success) {
64
                    addNotification({ style: "danger", msg: response.data })
65
                    return
3810 stevensc 66
                }
4817 stevensc 67
                setIsLiked(!isLiked)
68
            })
4816 stevensc 69
    }
3810 stevensc 70
 
4816 stevensc 71
    const htmlParsedText = (fullStringText) => {
72
        const fullText = parse(fullStringText)
73
        if (fullStringText.length > 500) {
4817 stevensc 74
            const shortenedString = fullStringText.substr(0, 500)
75
            const shortenedText = parse(`${shortenedString}... `)
4816 stevensc 76
            return (
77
                <>
78
                    {isReadMoreActive ? fullText : shortenedText}
79
                    <span className='cursor-pointer' onClick={readMoreHandler}>
80
                        {isReadMoreActive ? " Leer menos" : " Leer más"}
81
                    </span>
82
                </>
4817 stevensc 83
            )
4816 stevensc 84
        }
85
        return <p>{fullText}</p>
86
    }
3361 stevensc 87
 
4818 stevensc 88
    useEffect(() => {
89
        if (comments.length > 0) setShowComments(!showComments)
90
    }, [comments])
91
 
92
 
1 www 93
    return (
3760 stevensc 94
        <div className="container">
4096 stevensc 95
            <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
4816 stevensc 96
                <div className="col-12 col-md-8 p-0">
97
                    <div className='feed'>
98
                        <div className='feed__body'>
99
                            {post.image && <img src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`} className="Entradas" loading='lazy' />}
100
                        </div>
101
                        <div className='feed__body'>
102
                            <div className='feed__header'>
103
                                <div className='feed__info'>
104
                                    <h2>{post.title}</h2>
105
                                    <div className='time__elapse'>
106
                                        <p>{post.addedOn}</p>
107
                                        <AccessTimeIcon className='time__elapse-icon' />
4093 stevensc 108
                                    </div>
4816 stevensc 109
                                </div>
3761 stevensc 110
                            </div>
4816 stevensc 111
                            {post.description && htmlParsedText(post.description)}
3761 stevensc 112
                        </div>
4818 stevensc 113
                        <div className="px-3 d-flex align-items-center justify-content-between" style={{ gap: '5px' }}>
114
                            {!!externalShare && <span>{`${externalShare} enviados`}</span>}
4093 stevensc 115
                        </div>
4818 stevensc 116
                        <div className='feed__buttons'>
117
                            <InputOption
118
                                Icon={isLiked ? ThumbUpAltIcon : ThumbUpAltOutlinedIcon}
119
                                title='Like'
120
                                color={isLiked ? '#7405f9' : 'gray'}
121
                                onClick={() => handleLike(isLiked ? post.unlike_url : post.like_url)}
122
                            />
123
                            <InputOption
124
                                Icon={ChatOutlinedIcon}
125
                                title='Comment'
126
                                color='gray'
127
                                onClick={displayCommentSection}
128
                            />
129
                            <ExternalShareButton />
130
                        </div>
131
                        <div className='px-2 pb-2'>
132
                            <FeedCommentSection
133
                                feedId={post.uuid}
134
                                addUrl={post.comments_add_url}
135
                                comments={comments}
136
                                isShow={showComments}
137
                            />
138
                        </div>
3760 stevensc 139
                    </div>
1 www 140
                </div>
4098 stevensc 141
                <div className="col-12 col-md-4 p-0">
142
                    <HomeNews currentPost={post.uuid} />
4093 stevensc 143
                </div>
144
            </div>
145
        </div >
1 www 146
    )
147
}