Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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