Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5786 | Rev 5791 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5115 stevensc 1
/* eslint-disable camelcase */
3207 stevensc 2
/* eslint-disable react/prop-types */
5115 stevensc 3
import React, { useEffect, useState, useRef } from 'react'
4
import parse from 'html-react-parser'
5414 stevensc 5
import { useDispatch, useSelector } from 'react-redux'
5115 stevensc 6
import { axios } from '../../../utils'
5579 stevensc 7
import {
8
  EmailIcon,
9
  EmailShareButton,
10
  FacebookIcon,
11
  FacebookShareButton,
12
  RedditIcon,
13
  RedditShareButton,
14
  TelegramIcon,
15
  TelegramShareButton,
16
  TwitterIcon,
17
  TwitterShareButton,
18
  WhatsappIcon,
19
  WhatsappShareButton,
20
} from 'react-share'
5782 stevensc 21
import { feedTypes } from '../../../redux/feed/feed.types'
5115 stevensc 22
import { shareModalTypes } from '../../../redux/share-modal/shareModal.types'
23
import { openShareModal } from '../../../redux/share-modal/shareModal.actions'
24
import { addNotification } from '../../../redux/notification/notification.actions'
5782 stevensc 25
import useOutsideClick from '../../../hooks/useOutsideClick'
1034 stevensc 26
 
5115 stevensc 27
// Components
28
import FeedModal from './FeedModal'
29
import FeedHeader from './FeedHeader'
30
import FeedCommentSection from './feed-comment/FeedCommentSection'
5782 stevensc 31
import RecommendIcon from '@mui/icons-material/Recommend'
32
import FavoriteIcon from '@mui/icons-material/FavoriteTwoTone'
33
import VolunteerActivismIcon from '@mui/icons-material/VolunteerActivism'
34
import EmojiEmotionsIcon from '@mui/icons-material/EmojiEmotions'
35
import TungstenIcon from '@mui/icons-material/Tungsten'
5667 stevensc 36
import { ReactionButton } from './withReaction'
5115 stevensc 37
 
4017 stevensc 38
const Feed = ({ feed, owner_shared, image }) => {
1 www 39
  const {
40
    feed_unique,
41
    owner_name,
42
    owner_url,
43
    owner_image,
44
    owner_time_elapse,
45
    owner_file_image,
46
    owner_file_video,
47
    owner_file_document,
5706 stevensc 48
    owner_feed_type,
3207 stevensc 49
    feed_highlighted,
1 www 50
    feed_share_url,
51
    feed_delete_url,
52
    comments,
53
    comment_add_url,
5579 stevensc 54
    feed_share_external_url,
5115 stevensc 55
  } = feed
5781 stevensc 56
  const [totalComments, setTotalComments] = useState(comments.length)
5783 stevensc 57
  const [ownerReactions, setOwnerReaction] = useState(feed.feed_reactions)
5781 stevensc 58
  const [totalReactions, setTotalReactions] = useState(0)
5115 stevensc 59
  const [sharedState, setSharedState] = useState(owner_shared)
60
  const [shareUrl, setShareUrl] = useState('')
5781 stevensc 61
 
5115 stevensc 62
  const [showComments, setShowComments] = useState(false)
3308 stevensc 63
  const [shareOptions, setShareOptions] = useState(false)
5115 stevensc 64
  const [show, setShow] = useState(false)
1 www 65
 
5115 stevensc 66
  const shareContainer = useRef(null)
5781 stevensc 67
  const dispatch = useDispatch()
68
  const outsideClick = useOutsideClick(shareContainer)
1034 stevensc 69
 
5781 stevensc 70
  const reactionsOptions = [
71
    {
72
      type: 'r',
73
      icon: <RecommendIcon style={{ color: '#7405f9' }} />,
74
    },
75
    {
76
      type: 's',
77
      icon: <VolunteerActivismIcon style={{ color: '#6495ED' }} />,
78
    },
79
    {
80
      type: 'l',
81
      icon: <FavoriteIcon style={{ color: '#DF704D' }} />,
82
    },
83
    {
84
      type: 'i',
85
      icon: (
86
        <TungstenIcon
87
          style={{ color: '#F5BB5C', transform: 'rotate(180deg)' }}
88
        />
89
      ),
90
    },
91
    {
92
      type: 'f',
93
      icon: <EmojiEmotionsIcon style={{ color: '#FF7F50' }} />,
94
    },
95
  ]
1030 stevensc 96
 
4016 stevensc 97
  const getShareUrl = new Promise((resolve, reject) => {
98
    if (shareOptions) {
5579 stevensc 99
      axios
100
        .get(feed_share_external_url)
4016 stevensc 101
        .then(({ data }) => {
102
          if (!data.success) {
103
            dispatch(addNotification({ style: 'danger', msg: data.data }))
104
            setShareOptions(false)
105
            return reject(data.data)
106
          }
107
          setShareUrl(data.data)
108
          return resolve(data.data)
109
        })
110
        .catch((err) => reject(err))
4015 stevensc 111
    }
5115 stevensc 112
  })
4015 stevensc 113
 
5781 stevensc 114
  const saveReaction = (type) => {
115
    const reactionTypesUrl = {
116
      r: feed.feed_save_reaction_recommended_url,
117
      s: feed.feed_save_reaction_support_url,
118
      l: feed.feed_save_reaction_love_url,
119
      i: feed.feed_save_reaction_interest_url,
120
      f: feed.feed_save_reaction_fun_url,
121
    }
122
 
123
    axios.post(reactionTypesUrl[type]).then((res) => {
5579 stevensc 124
      const { success, data } = res.data
5781 stevensc 125
 
5579 stevensc 126
      if (!success) {
5781 stevensc 127
        dispatch(addNotification({ style: 'danger', msg: data }))
5579 stevensc 128
      }
5781 stevensc 129
 
5786 stevensc 130
      setOwnerReaction(data.reactions)
5787 stevensc 131
      return true
5579 stevensc 132
    })
5781 stevensc 133
  }
1 www 134
 
5781 stevensc 135
  const deleteReaction = () => {
5785 stevensc 136
    axios.post(feed.feed_delete_reaction_url).then((res) => {
5781 stevensc 137
      const { success, data } = res.data
138
 
139
      if (!success) {
140
        dispatch(addNotification({ style: 'danger', msg: data }))
141
        return
142
      }
143
 
5786 stevensc 144
      setOwnerReaction(data.reactions)
5787 stevensc 145
      return true
5781 stevensc 146
    })
147
  }
148
 
3962 stevensc 149
  const displayComments = () => setShowComments(!showComments)
150
 
5781 stevensc 151
  const btnShareHandler = () => {
5579 stevensc 152
    dispatch(
153
      openShareModal(
154
        feed_share_url,
155
        shareModalTypes.SHARE,
156
        feedTypes.DASHBOARD,
157
        feed_unique
158
      )
159
    )
5781 stevensc 160
  }
1 www 161
 
5781 stevensc 162
  useEffect(() => setSharedState(owner_shared), [owner_shared])
163
 
164
  useEffect(() => outsideClick && setShareOptions(false), [outsideClick])
165
 
166
  useEffect(() => {
5783 stevensc 167
    const feedReactions = ownerReactions.reduce(
5781 stevensc 168
      (acc, reaction) => acc + Number(reaction.total),
169
 
170
    )
171
    setTotalReactions(feedReactions)
5783 stevensc 172
  }, [ownerReactions])
5781 stevensc 173
 
1 www 174
  return (
4017 stevensc 175
    <>
5579 stevensc 176
      <FeedModal isShow={show} handleClose={() => setShow(false)} feed={feed} />
5449 stevensc 177
      <div className={`feed ${feed_highlighted ? 'highlighted' : ''}`}>
3630 stevensc 178
        <FeedHeader
179
          ownerName={owner_name}
180
          ownerImage={owner_image}
181
          ownerTimeElapse={owner_time_elapse}
182
          ownerUrl={owner_url}
183
          feedDeleteUrl={feed_delete_url}
184
          feedUnique={feed_unique}
5706 stevensc 185
          feedType={owner_feed_type}
3630 stevensc 186
        />
5579 stevensc 187
        <div
188
          onClick={() =>
189
            (owner_file_image || owner_file_video || owner_file_document) &&
190
            setShow(true)
191
          }
718 steven 192
        >
4017 stevensc 193
          <Feed.Content
5115 stevensc 194
            isShare={!!feed.shared_name}
4017 stevensc 195
            ownerFileImage={feed.owner_file_image}
196
            ownerFileVideo={feed.owner_file_video}
197
            ownerFileImagePreview={feed.owner_file_image_preview}
198
            ownerFileDocument={feed.owner_file_document}
199
            ownerDescription={feed.owner_description}
200
            sharedItem={{
201
              name: feed.shared_name,
202
              image: feed.shared_image,
203
              time_elapse: feed.shared_time_elapse,
204
              description: feed.shared_description,
205
              file_video: feed.shared_file_video,
206
              file_image_preview: feed.shared_file_image_preview,
207
              file_image: feed.shared_file_image,
5579 stevensc 208
              file_document: feed.shared_file_document,
4017 stevensc 209
            }}
210
          />
718 steven 211
        </div>
5783 stevensc 212
        <div className="reactions-counter">
5781 stevensc 213
          {reactionsOptions
214
            .filter((option) =>
5783 stevensc 215
              ownerReactions.find(
5781 stevensc 216
                (reaction) => reaction.reaction === option.type
217
              )
218
            )
219
            .map((reaction) => reaction.icon)}
5785 stevensc 220
          <span>{totalReactions} reacciones</span>
5781 stevensc 221
        </div>
5706 stevensc 222
        <ul className="reactions-list">
223
          <li>
5771 stevensc 224
            <ReactionButton
5781 stevensc 225
              onSelect={saveReaction}
226
              onDelete={deleteReaction}
5772 stevensc 227
              myReaction={feed.feed_my_reaction}
5771 stevensc 228
            />
5706 stevensc 229
          </li>
230
          <li>
231
            <button
232
              type="button"
233
              id={`btn-comments-${feed_unique}`}
234
              className="btn-indicator"
235
              onClick={displayComments}
236
            >
237
              <img src="/images/icons/message.png" className="mr-1 img-icon" />
238
              {totalComments}
239
            </button>
240
          </li>
241
          <li>
242
            <button
243
              type="button"
244
              id={`btn-share-${feed_unique}`}
245
              className="btn-indicator"
246
              onClick={btnShareHandler}
247
            >
248
              <img src="/images/icons/share.png" className="mr-1 img-icon" />
249
              {sharedState}
250
            </button>
251
          </li>
252
          <li className="position-relative">
253
            <button
254
              type="button"
255
              className="btn-indicator"
256
              onClick={() => setShareOptions(!shareOptions)}
257
            >
258
              <i className="mr-1 far fa-share-square" />
259
            </button>
260
            {shareOptions && (
261
              <div className="ext_share" ref={shareContainer}>
262
                <FacebookShareButton
263
                  beforeOnClick={() => getShareUrl}
264
                  url={shareUrl}
265
                >
266
                  <FacebookIcon size={32} round />
267
                </FacebookShareButton>
268
                <TwitterShareButton
269
                  beforeOnClick={() => getShareUrl}
270
                  url={shareUrl}
271
                >
272
                  <TwitterIcon size={32} round />
273
                </TwitterShareButton>
274
                <TelegramShareButton
275
                  beforeOnClick={() => getShareUrl}
276
                  url={shareUrl}
277
                >
278
                  <TelegramIcon size={32} round />
279
                </TelegramShareButton>
280
                <WhatsappShareButton
281
                  beforeOnClick={() => getShareUrl}
282
                  url={shareUrl}
283
                >
284
                  <WhatsappIcon size={32} round />
285
                </WhatsappShareButton>
286
                <RedditShareButton
287
                  beforeOnClick={() => getShareUrl}
288
                  url={shareUrl}
289
                >
290
                  <RedditIcon size={32} round />
291
                </RedditShareButton>
292
                <EmailShareButton
293
                  beforeOnClick={() => getShareUrl}
294
                  url={shareUrl}
295
                >
296
                  <EmailIcon size={32} round />
297
                </EmailShareButton>
298
              </div>
299
            )}
300
          </li>
301
        </ul>
302
 
3943 stevensc 303
        <FeedCommentSection
304
          feedId={feed.feed_unique}
305
          image={image}
306
          addUrl={comment_add_url}
5583 stevensc 307
          updateTotalComments={(total) => setTotalComments(total)}
5579 stevensc 308
          currentComments={comments}
3962 stevensc 309
          isShow={showComments}
3943 stevensc 310
        />
5115 stevensc 311
      </div>
4017 stevensc 312
    </>
5115 stevensc 313
  )
314
}
1 www 315
 
4017 stevensc 316
const Content = ({
317
  showDescription = true,
318
  ownerFileImage,
319
  ownerFileVideo,
320
  ownerFileImagePreview,
321
  ownerFileDocument,
322
  ownerDescription,
323
  isShare,
5579 stevensc 324
  sharedItem,
4017 stevensc 325
}) => {
5579 stevensc 326
  const labels = useSelector((state) => state.labels)
4017 stevensc 327
  return (
328
    <div className="job_descp">
5579 stevensc 329
      {showDescription && (
4017 stevensc 330
        <Feed.Description ownerDescription={ownerDescription} />
5579 stevensc 331
      )}
332
      {ownerFileImage && (
333
        <img src={ownerFileImage} className="Entradas" loading="lazy" />
334
      )}
335
      {ownerFileVideo && (
4017 stevensc 336
        <video
337
          src={ownerFileVideo}
338
          controls
339
          poster={ownerFileImagePreview}
340
          preload="none"
341
        />
5579 stevensc 342
      )}
343
      {ownerFileDocument && (
4017 stevensc 344
        <a href={ownerFileDocument} target="_blank" rel="noreferrer">
5414 stevensc 345
          {labels.DOWNLOAD}
4017 stevensc 346
        </a>
5579 stevensc 347
      )}
348
      {isShare && (
4017 stevensc 349
        <Feed.SharedContent
350
          name={sharedItem.name}
351
          image={sharedItem.image}
352
          timeElapse={sharedItem.time_elapse}
353
          description={sharedItem.description}
354
          fileVideo={sharedItem.file_video}
355
          fileImagePreview={sharedItem.file_image_preview}
356
          fileImage={sharedItem.file_image}
357
          fileDocument={sharedItem.file_document}
358
        />
5579 stevensc 359
      )}
4017 stevensc 360
    </div>
361
  )
362
}
363
 
364
const Description = ({ ownerDescription }) => {
5115 stevensc 365
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
5579 stevensc 366
  const labels = useSelector((state) => state.labels)
4017 stevensc 367
 
368
  const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
369
 
370
  const htmlParsedText = (fullStringText) => {
371
    const fullText = parse(fullStringText)
372
    if (fullStringText.length > 500) {
5115 stevensc 373
      const shortenedString = fullStringText.substr(0, 500)
374
      const shortenedText = parse(`${shortenedString}... `)
4017 stevensc 375
      return (
376
        <p>
377
          {isReadMoreActive ? fullText : shortenedText}
5579 stevensc 378
          <span className="cursor-pointer" onClick={readMoreHandler}>
5414 stevensc 379
            {isReadMoreActive ? labels.READ_LESS : labels.READ_MORE}
4017 stevensc 380
          </span>
381
        </p>
5115 stevensc 382
      )
4017 stevensc 383
    }
384
    return <p>{fullText}</p>
5115 stevensc 385
  }
4017 stevensc 386
 
387
  return (
5579 stevensc 388
    <div className="show-read-more">{htmlParsedText(ownerDescription)}</div>
4017 stevensc 389
  )
390
}
391
 
392
const SharedContent = ({
393
  name,
394
  image,
395
  timeElapse,
396
  description,
397
  fileVideo,
398
  fileImagePreview,
399
  fileImage,
5579 stevensc 400
  fileDocument,
4017 stevensc 401
}) => {
5115 stevensc 402
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
5579 stevensc 403
  const labels = useSelector((state) => state.labels)
4017 stevensc 404
 
405
  const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
406
 
407
  const htmlParsedText = (fullStringText) => {
408
    const fullText = parse(fullStringText)
409
    if (fullStringText.length > 500) {
5115 stevensc 410
      const shortenedString = fullStringText.substr(0, 500)
411
      const shortenedText = parse(`${shortenedString}... `)
4017 stevensc 412
      return (
413
        <p>
414
          {isReadMoreActive ? fullText : shortenedText}
5579 stevensc 415
          <span className="cursor-pointer" onClick={readMoreHandler}>
5414 stevensc 416
            {isReadMoreActive ? labels.READ_LESS : labels.READ_MORE}
4017 stevensc 417
          </span>
418
        </p>
5115 stevensc 419
      )
4017 stevensc 420
    }
421
    return <p>{fullText}</p>
5115 stevensc 422
  }
4017 stevensc 423
 
424
  return (
425
    <div className="shared-post-bar">
426
      <div className="post-bar">
427
        <div className="post_topbar">
428
          <div className="usy-dt">
5579 stevensc 429
            <img src={image} alt="" style={{ width: '50px', height: 'auto' }} />
4017 stevensc 430
            <div className="usy-name">
431
              <h3>{name}</h3>
5579 stevensc 432
              <span>{timeElapse}</span>
4017 stevensc 433
            </div>
434
          </div>
435
        </div>
436
        <div className="job_descp">
5579 stevensc 437
          <div className="show-read-more">{htmlParsedText(description)}</div>
438
          {fileImage && (
439
            <img src={fileImage} className="Entradas" loading="lazy" />
440
          )}
441
          {fileVideo && (
4017 stevensc 442
            <video
443
              src={fileVideo}
444
              controls
445
              poster={fileImagePreview}
446
              preload="none"
447
            />
5579 stevensc 448
          )}
449
          {fileDocument && (
4017 stevensc 450
            <a href={fileDocument} target="_blank" rel="noreferrer">
5414 stevensc 451
              {labels.DOWNLOAD}
4017 stevensc 452
            </a>
5579 stevensc 453
          )}
4017 stevensc 454
        </div>
455
      </div>
456
    </div>
457
  )
458
}
459
 
460
Feed.SharedContent = SharedContent
461
Feed.Description = Description
462
Feed.Content = Content
463
 
5115 stevensc 464
export default React.memo(Feed)