Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4816 | Rev 4818 | 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 */
4816 stevensc 2
import React, { 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'
21
 
4816 stevensc 22
export default function PostView({ post = {
23
    url: "",
24
    file: "imagengrupo.png",
25
    comments_url: "/post/344ccca7-6260-4564-93cc-85ed7682bec2/comments",
26
    comments_add_url: "/post/344ccca7-6260-4564-93cc-85ed7682bec2/comments/add"
27
}
28
}) {
29
    const [isLiked, setIsLiked] = useState(post.is_liked)
30
    const [externalShare, setExternalShare] = useState(post.total_share_external)
31
    const [isReadMoreActive, setIsReadMoreActive] = useState(false)
32
    const [showComments, setShowComments] = useState(false)
3810 stevensc 33
 
4816 stevensc 34
    const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
35
 
36
    const displayCommentSection = () => {
37
        axios.get(post.comments_url)
38
        setShowComments(!showComments)
39
    }
40
 
41
    const ExternalShareButton = withExternalShare(InputOption, post.share_external_url, {
42
        Icon: SendOutlinedIcon,
43
        color: 'gray',
44
        title: 'Send',
45
        shareUrl: post.share_increment_external_counter_url,
46
        setValue: handleExternalShare
47
    })
48
 
49
    const handleExternalShare = (value) => setExternalShare(value)
50
 
51
    const handleLike = (url) => {
52
        axios.post(url)
53
            .then(({ data: response }) => {
54
                if (!response.success) {
55
                    addNotification({ style: "danger", msg: response.data })
56
                    return
3810 stevensc 57
                }
4817 stevensc 58
                setIsLiked(!isLiked)
59
            })
4816 stevensc 60
    }
3810 stevensc 61
 
4816 stevensc 62
    const htmlParsedText = (fullStringText) => {
63
        const fullText = parse(fullStringText)
64
        if (fullStringText.length > 500) {
4817 stevensc 65
            const shortenedString = fullStringText.substr(0, 500)
66
            const shortenedText = parse(`${shortenedString}... `)
4816 stevensc 67
            return (
68
                <>
69
                    {isReadMoreActive ? fullText : shortenedText}
70
                    <span className='cursor-pointer' onClick={readMoreHandler}>
71
                        {isReadMoreActive ? " Leer menos" : " Leer más"}
72
                    </span>
73
                </>
4817 stevensc 74
            )
4816 stevensc 75
        }
76
        return <p>{fullText}</p>
77
    }
3361 stevensc 78
 
1 www 79
    return (
3760 stevensc 80
        <div className="container">
4096 stevensc 81
            <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
4816 stevensc 82
                <div className="col-12 col-md-8 p-0">
83
                    <div className='feed'>
84
                        <div className='feed__body'>
85
                            {post.image && <img src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`} className="Entradas" loading='lazy' />}
86
                        </div>
87
                        <div className='feed__body'>
88
                            <div className='feed__header'>
89
                                <div className='feed__info'>
90
                                    <h2>{post.title}</h2>
91
                                    <div className='time__elapse'>
92
                                        <p>{post.addedOn}</p>
93
                                        <AccessTimeIcon className='time__elapse-icon' />
4093 stevensc 94
                                    </div>
4816 stevensc 95
                                </div>
3761 stevensc 96
                            </div>
4816 stevensc 97
                            {post.description && htmlParsedText(post.description)}
3761 stevensc 98
                        </div>
4816 stevensc 99
                        <div className="px-3 d-flex align-items-center justify-content-between">
100
                            <div className="d-inline-flex align-items-center" style={{ gap: '5px' }}>
101
                                {!!externalShare && <span>{`${externalShare} enviados`}</span>}
102
                            </div>
103
                            <div className='feed__buttons'>
104
                                <InputOption
105
                                    Icon={isLiked ? ThumbUpAltIcon : ThumbUpAltOutlinedIcon}
106
                                    title='Like'
107
                                    color={isLiked ? '#7405f9' : 'gray'}
108
                                    onClick={() => handleLike(isLiked ? post.unlike_url : post.like_url)}
109
                                />
110
                                <InputOption
111
                                    Icon={ChatOutlinedIcon}
112
                                    title='Comment'
113
                                    color='gray'
114
                                    onClick={displayCommentSection}
115
                                />
116
                                <ExternalShareButton />
117
                            </div>
4093 stevensc 118
                        </div>
3760 stevensc 119
                    </div>
1 www 120
                </div>
4098 stevensc 121
                <div className="col-12 col-md-4 p-0">
122
                    <HomeNews currentPost={post.uuid} />
4093 stevensc 123
                </div>
124
            </div>
125
        </div >
1 www 126
    )
127
}