| 7129 |
stevensc |
1 |
import React, { useEffect, useState } from 'react'
|
|
|
2 |
import { axios } from '../../utils'
|
|
|
3 |
import { useDispatch, useSelector } from 'react-redux'
|
|
|
4 |
import { Col, Container, Row } from 'react-bootstrap'
|
|
|
5 |
import { getBackendVars } from '../../services/backendVars'
|
|
|
6 |
import { addNotification } from '../../redux/notification/notification.actions'
|
|
|
7 |
import parse from 'html-react-parser'
|
|
|
8 |
|
|
|
9 |
import TungstenIcon from '@mui/icons-material/Tungsten'
|
|
|
10 |
import RecommendIcon from '@mui/icons-material/Recommend'
|
|
|
11 |
import AccessTimeIcon from '@mui/icons-material/AccessTime'
|
|
|
12 |
import FavoriteIcon from '@mui/icons-material/FavoriteTwoTone'
|
|
|
13 |
import SendOutlinedIcon from '@mui/icons-material/SendOutlined'
|
|
|
14 |
import ChatOutlinedIcon from '@mui/icons-material/ChatOutlined'
|
|
|
15 |
import EmojiEmotionsIcon from '@mui/icons-material/EmojiEmotions'
|
|
|
16 |
import VolunteerActivismIcon from '@mui/icons-material/VolunteerActivism'
|
|
|
17 |
|
|
|
18 |
import HomeNews from '../../components/widgets/default/HomeNews'
|
|
|
19 |
import CommentSection from '../../components/feed/CommentSection'
|
|
|
20 |
import withExternalShare from '../../components/feed/linkedin/withExternalShare'
|
|
|
21 |
import InputOption from '../../components/feed/linkedin/InputOption'
|
|
|
22 |
import ReactionsButton from '../../components/UI/buttons/ReactionsButton'
|
|
|
23 |
import { useLocation } from 'react-router-dom'
|
|
|
24 |
|
|
|
25 |
const PostViewPage = () => {
|
|
|
26 |
const [post, setPost] = useState({})
|
|
|
27 |
const [totalSends, setTotalSends] = useState(0)
|
|
|
28 |
const [reactions, setReactions] = useState([])
|
|
|
29 |
const [myReaction, setMyReaction] = useState('')
|
|
|
30 |
const [totalReactions, setTotalReactions] = useState(0)
|
|
|
31 |
const [comments, setComments] = useState([])
|
|
|
32 |
const [readMore, setReadMore] = useState(false)
|
|
|
33 |
const [showComments, setShowComments] = useState(false)
|
|
|
34 |
const labels = useSelector(({ intl }) => intl.labels)
|
|
|
35 |
const dispatch = useDispatch()
|
|
|
36 |
const { pathname } = useLocation()
|
|
|
37 |
|
|
|
38 |
const reactionsOptions = [
|
|
|
39 |
{
|
|
|
40 |
type: 'r',
|
|
|
41 |
icon: <RecommendIcon style={{ color: '#7405f9' }} />,
|
|
|
42 |
},
|
|
|
43 |
{
|
|
|
44 |
type: 's',
|
|
|
45 |
icon: <VolunteerActivismIcon style={{ color: '#6495ED' }} />,
|
|
|
46 |
},
|
|
|
47 |
{
|
|
|
48 |
type: 'l',
|
|
|
49 |
icon: <FavoriteIcon style={{ color: '#DF704D' }} />,
|
|
|
50 |
},
|
|
|
51 |
{
|
|
|
52 |
type: 'i',
|
|
|
53 |
icon: (
|
|
|
54 |
<TungstenIcon
|
|
|
55 |
style={{ color: '#F5BB5C', transform: 'rotate(180deg)' }}
|
|
|
56 |
/>
|
|
|
57 |
),
|
|
|
58 |
},
|
|
|
59 |
{
|
|
|
60 |
type: 'f',
|
|
|
61 |
icon: <EmojiEmotionsIcon style={{ color: '#FF7F50' }} />,
|
|
|
62 |
},
|
|
|
63 |
]
|
|
|
64 |
|
|
|
65 |
const readMoreHandler = () => setReadMore(!readMore)
|
|
|
66 |
|
|
|
67 |
const displayCommentSection = () => {
|
|
|
68 |
setShowComments(!showComments)
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
const getComments = async () => {
|
|
|
72 |
axios.get(post.comments_url).then((response) => {
|
|
|
73 |
const { data, success } = response.data
|
|
|
74 |
|
|
|
75 |
if (!success) {
|
|
|
76 |
addNotification({ style: 'danger', msg: data })
|
|
|
77 |
return
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
setComments(data)
|
|
|
81 |
})
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
const handleExternalShare = (value) => {
|
|
|
85 |
setTotalSends(value)
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
const ExternalShareButton = withExternalShare(
|
|
|
89 |
InputOption,
|
|
|
90 |
post.share_external_url,
|
|
|
91 |
{
|
|
|
92 |
Icon: SendOutlinedIcon,
|
|
|
93 |
color: 'gray',
|
|
|
94 |
title: 'Enviar',
|
|
|
95 |
shareUrl: post.share_increment_external_counter_url,
|
|
|
96 |
setValue: handleExternalShare,
|
|
|
97 |
withTitle: true,
|
|
|
98 |
}
|
|
|
99 |
)
|
|
|
100 |
|
|
|
101 |
const htmlParsedText = (fullStringText) => {
|
|
|
102 |
const fullText = parse(fullStringText)
|
|
|
103 |
if (fullStringText.length > 500) {
|
|
|
104 |
const shortenedString = fullStringText.substr(0, 500)
|
|
|
105 |
const shortenedText = parse(`${shortenedString}... `)
|
|
|
106 |
return (
|
|
|
107 |
<>
|
|
|
108 |
{readMore ? fullText : shortenedText}
|
|
|
109 |
<span className="cursor-pointer" onClick={readMoreHandler}>
|
|
|
110 |
{readMore ? ' Leer menos' : ' Leer más'}
|
|
|
111 |
</span>
|
|
|
112 |
</>
|
|
|
113 |
)
|
|
|
114 |
}
|
|
|
115 |
return <p>{fullText}</p>
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
useEffect(() => {
|
|
|
119 |
getBackendVars(pathname)
|
|
|
120 |
.then((post) => {
|
|
|
121 |
setMyReaction(post.my_reaction)
|
|
|
122 |
setTotalSends(post.total_share_external)
|
|
|
123 |
setPost(post)
|
|
|
124 |
})
|
|
|
125 |
.catch((error) => {
|
|
|
126 |
dispatch(
|
|
|
127 |
addNotification({
|
|
|
128 |
style: 'danger',
|
| 7201 |
stevensc |
129 |
message: 'Error interno. Por favor, inténtelo de nuevo más tarde.',
|
| 7129 |
stevensc |
130 |
})
|
|
|
131 |
)
|
|
|
132 |
throw new Error(error)
|
|
|
133 |
})
|
|
|
134 |
}, [])
|
|
|
135 |
|
|
|
136 |
useEffect(() => {
|
|
|
137 |
if (showComments && !comments.length) {
|
|
|
138 |
getComments()
|
|
|
139 |
}
|
|
|
140 |
}, [showComments])
|
|
|
141 |
|
|
|
142 |
useEffect(() => {
|
|
|
143 |
const feedReactions = reactions.reduce(
|
|
|
144 |
(acc, reaction) => acc + Number(reaction.total),
|
|
|
145 |
|
|
|
146 |
)
|
|
|
147 |
|
|
|
148 |
setTotalReactions(feedReactions)
|
|
|
149 |
}, [reactions])
|
|
|
150 |
|
|
|
151 |
return (
|
|
|
152 |
<Container>
|
|
|
153 |
<Row>
|
|
|
154 |
<Col md="8">
|
|
|
155 |
<div className="feed">
|
|
|
156 |
<div className="feed__body">
|
|
|
157 |
{post.image && (
|
|
|
158 |
<img
|
|
|
159 |
src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`}
|
|
|
160 |
/>
|
|
|
161 |
)}
|
|
|
162 |
</div>
|
|
|
163 |
<div className="feed__body">
|
|
|
164 |
<div className="feed__header">
|
|
|
165 |
<div className="feed__info">
|
|
|
166 |
<h2>{post.title}</h2>
|
|
|
167 |
<div className="time__elapse">
|
|
|
168 |
<p>{post.addedOn}</p>
|
|
|
169 |
<AccessTimeIcon className="time__elapse-icon" />
|
|
|
170 |
</div>
|
|
|
171 |
</div>
|
|
|
172 |
</div>
|
|
|
173 |
{post.description && htmlParsedText(post.description)}
|
|
|
174 |
{post.file && (
|
|
|
175 |
<a href={post.file} download>
|
|
|
176 |
<img
|
|
|
177 |
className="pdf"
|
|
|
178 |
src="/images/extension/pdf.png"
|
|
|
179 |
alt="pdf"
|
|
|
180 |
/>
|
|
|
181 |
</a>
|
|
|
182 |
)}
|
|
|
183 |
</div>
|
|
|
184 |
<div className="d-flex justify-content-between align-items-center px-3">
|
|
|
185 |
<div className="reactions-counter">
|
|
|
186 |
{reactionsOptions
|
|
|
187 |
.filter((option) =>
|
|
|
188 |
reactions.find(({ reaction }) => reaction === option.type)
|
|
|
189 |
)
|
|
|
190 |
.map((reaction) => reaction.icon)}
|
|
|
191 |
<span>{totalReactions} reacciones</span>
|
|
|
192 |
</div>
|
| 7131 |
stevensc |
193 |
{!!totalSends && (
|
| 7129 |
stevensc |
194 |
<span>{`${totalSends} ${labels.sends?.toLowerCase()}`}</span>
|
|
|
195 |
)}
|
|
|
196 |
</div>
|
|
|
197 |
<div className="feed__buttons">
|
|
|
198 |
<ReactionsButton
|
| 7133 |
stevensc |
199 |
className="btn feed__share-option position-relative"
|
| 7129 |
stevensc |
200 |
currentReaction={myReaction}
|
|
|
201 |
withLabel
|
|
|
202 |
onChange={(newReactions) => setReactions(newReactions)}
|
|
|
203 |
/>
|
|
|
204 |
<InputOption
|
|
|
205 |
Icon={ChatOutlinedIcon}
|
|
|
206 |
title={labels.comments}
|
|
|
207 |
color="gray"
|
|
|
208 |
onClick={displayCommentSection}
|
|
|
209 |
withTitle
|
|
|
210 |
/>
|
|
|
211 |
<ExternalShareButton />
|
|
|
212 |
</div>
|
|
|
213 |
<div className="px-2 pb-2">
|
|
|
214 |
<CommentSection
|
|
|
215 |
addUrl={post.comments_add_url}
|
|
|
216 |
currentComments={comments}
|
|
|
217 |
isShow={showComments}
|
|
|
218 |
/>
|
|
|
219 |
</div>
|
|
|
220 |
</div>
|
|
|
221 |
</Col>
|
|
|
222 |
<Col md="4">
|
|
|
223 |
<HomeNews currentPost={post.uuid} />
|
|
|
224 |
</Col>
|
|
|
225 |
</Row>
|
|
|
226 |
</Container>
|
|
|
227 |
)
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
export default PostViewPage
|