Rev 4816 | Rev 4818 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
/* eslint-disable react/prop-types */import React, { useState } from 'react'import { axios } from '../../utils'import { addNotification } from '../../redux/notification/notification.actions'import parse from 'html-react-parser'// Componentsimport HomeNews from '../components/home-section/HomeNews'import InputOption from '../templates/linkedin/Feed/InputOption'import withExternalShare from '../templates/linkedin/Feed/withExternalShare'// Iconsimport ThumbUpAltOutlinedIcon from '@mui/icons-material/ThumbUpAltOutlined'import ThumbUpAltIcon from '@mui/icons-material/ThumbUpAlt'import ChatOutlinedIcon from '@mui/icons-material/ChatOutlined'import SendOutlinedIcon from '@mui/icons-material/SendOutlined'import AccessTimeIcon from '@mui/icons-material/AccessTime'// Stylesimport '../templates/linkedin/Feed/Feed.scss'export default function PostView({ post = {url: "",file: "imagengrupo.png",comments_url: "/post/344ccca7-6260-4564-93cc-85ed7682bec2/comments",comments_add_url: "/post/344ccca7-6260-4564-93cc-85ed7682bec2/comments/add"}}) {const [isLiked, setIsLiked] = useState(post.is_liked)const [externalShare, setExternalShare] = useState(post.total_share_external)const [isReadMoreActive, setIsReadMoreActive] = useState(false)const [showComments, setShowComments] = useState(false)const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)const displayCommentSection = () => {axios.get(post.comments_url)setShowComments(!showComments)}const ExternalShareButton = withExternalShare(InputOption, post.share_external_url, {Icon: SendOutlinedIcon,color: 'gray',title: 'Send',shareUrl: post.share_increment_external_counter_url,setValue: handleExternalShare})const handleExternalShare = (value) => setExternalShare(value)const handleLike = (url) => {axios.post(url).then(({ data: response }) => {if (!response.success) {addNotification({ style: "danger", msg: response.data })return}setIsLiked(!isLiked)})}const htmlParsedText = (fullStringText) => {const fullText = parse(fullStringText)if (fullStringText.length > 500) {const shortenedString = fullStringText.substr(0, 500)const shortenedText = parse(`${shortenedString}... `)return (<>{isReadMoreActive ? fullText : shortenedText}<span className='cursor-pointer' onClick={readMoreHandler}>{isReadMoreActive ? " Leer menos" : " Leer más"}</span></>)}return <p>{fullText}</p>}return (<div className="container"><div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}><div className="col-12 col-md-8 p-0"><div className='feed'><div className='feed__body'>{post.image && <img src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`} className="Entradas" loading='lazy' />}</div><div className='feed__body'><div className='feed__header'><div className='feed__info'><h2>{post.title}</h2><div className='time__elapse'><p>{post.addedOn}</p><AccessTimeIcon className='time__elapse-icon' /></div></div></div>{post.description && htmlParsedText(post.description)}</div><div className="px-3 d-flex align-items-center justify-content-between"><div className="d-inline-flex align-items-center" style={{ gap: '5px' }}>{!!externalShare && <span>{`${externalShare} enviados`}</span>}</div><div className='feed__buttons'><InputOptionIcon={isLiked ? ThumbUpAltIcon : ThumbUpAltOutlinedIcon}title='Like'color={isLiked ? '#7405f9' : 'gray'}onClick={() => handleLike(isLiked ? post.unlike_url : post.like_url)}/><InputOptionIcon={ChatOutlinedIcon}title='Comment'color='gray'onClick={displayCommentSection}/><ExternalShareButton /></div></div></div></div><div className="col-12 col-md-4 p-0"><HomeNews currentPost={post.uuid} /></div></div></div >)}