Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5608 | Rev 5812 | 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 */
4821 stevensc 2
import React, { useEffect, 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'
4818 stevensc 21
import FeedCommentSection from '../components/feed/feed-comment/FeedCommentSection'
5617 stevensc 22
import { useDispatch } from 'react-redux'
23
import { setIntlLabels } from '../../redux/intl/intl.action'
4817 stevensc 24
 
5617 stevensc 25
export default function PostView({ post, labels }) {
5118 stevensc 26
  const [isLiked, setIsLiked] = useState(post.is_liked)
27
  const [externalShare, setExternalShare] = useState(post.total_share_external)
28
  const [comments, setComments] = useState([])
29
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
30
  const [showComments, setShowComments] = useState(false)
5617 stevensc 31
  const dispatch = useDispatch()
3810 stevensc 32
 
5118 stevensc 33
  const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
4816 stevensc 34
 
5118 stevensc 35
  const displayCommentSection = () => {
36
    setShowComments(!showComments)
37
  }
4821 stevensc 38
 
5118 stevensc 39
  const getComments = async () => {
5607 stevensc 40
    await axios.get(post.comments_url).then(({ data: response }) => {
41
      if (!response.success) {
42
        addNotification({ style: 'danger', msg: response.data })
43
        return
44
      }
4818 stevensc 45
 
5607 stevensc 46
      setComments(response.data)
47
    })
5118 stevensc 48
  }
4816 stevensc 49
 
5118 stevensc 50
  const handleExternalShare = (value) => setExternalShare(value)
4816 stevensc 51
 
5607 stevensc 52
  const ExternalShareButton = withExternalShare(
53
    InputOption,
54
    post.share_external_url,
55
    {
56
      Icon: SendOutlinedIcon,
57
      color: 'gray',
58
      title: 'Enviar',
59
      shareUrl: post.share_increment_external_counter_url,
60
      setValue: handleExternalShare,
61
    }
62
  )
4816 stevensc 63
 
5118 stevensc 64
  const handleLike = (url) => {
5607 stevensc 65
    axios.post(url).then(({ data: response }) => {
66
      if (!response.success) {
67
        addNotification({ style: 'danger', msg: response.data })
68
        return
69
      }
70
      setIsLiked(!isLiked)
71
    })
5118 stevensc 72
  }
3810 stevensc 73
 
5118 stevensc 74
  const htmlParsedText = (fullStringText) => {
75
    const fullText = parse(fullStringText)
76
    if (fullStringText.length > 500) {
77
      const shortenedString = fullStringText.substr(0, 500)
78
      const shortenedText = parse(`${shortenedString}... `)
79
      return (
5607 stevensc 80
        <>
81
          {isReadMoreActive ? fullText : shortenedText}
82
          <span className="cursor-pointer" onClick={readMoreHandler}>
83
            {isReadMoreActive ? ' Leer menos' : ' Leer más'}
84
          </span>
85
        </>
5118 stevensc 86
      )
4816 stevensc 87
    }
5118 stevensc 88
    return <p>{fullText}</p>
89
  }
3361 stevensc 90
 
5118 stevensc 91
  useEffect(() => {
5617 stevensc 92
    dispatch(setIntlLabels(labels))
93
  }, [])
94
 
95
  useEffect(() => {
5118 stevensc 96
    if (showComments && !comments.length) getComments()
97
  }, [showComments])
4821 stevensc 98
 
5118 stevensc 99
  return (
5607 stevensc 100
    <div className="container">
101
      <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
102
        <div className="col-12 col-md-8 p-0">
103
          <div className="feed">
104
            <div className="feed__body">
105
              {post.image && (
106
                <img
107
                  src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`}
108
                  className="Entradas"
109
                  loading="lazy"
110
                />
111
              )}
112
            </div>
113
            <div className="feed__body">
114
              <div className="feed__header">
115
                <div className="feed__info">
116
                  <h2>{post.title}</h2>
117
                  <div className="time__elapse">
118
                    <p>{post.addedOn}</p>
119
                    <AccessTimeIcon className="time__elapse-icon" />
120
                  </div>
1 www 121
                </div>
5607 stevensc 122
              </div>
123
              {post.description && htmlParsedText(post.description)}
4093 stevensc 124
            </div>
5607 stevensc 125
            <div
126
              className="px-3 d-flex align-items-center justify-content-end"
127
              style={{ gap: '5px' }}
128
            >
129
              {!!externalShare && (
130
                <span>{`${externalShare} ${LABELS.SENDS.toLowerCase()}`}</span>
131
              )}
132
            </div>
133
            <div className="feed__buttons">
134
              <InputOption
135
                Icon={isLiked ? ThumbUpAltIcon : ThumbUpAltOutlinedIcon}
136
                title={isLiked ? LABELS.UNLIKE : LABELS.LIKE}
137
                color={isLiked ? '#7405f9' : 'gray'}
138
                onClick={() =>
139
                  handleLike(isLiked ? post.unlike_url : post.like_url)
140
                }
141
              />
142
              <InputOption
143
                Icon={ChatOutlinedIcon}
144
                title={LABELS.COMMENTS}
145
                color="gray"
146
                onClick={displayCommentSection}
147
              />
148
              <ExternalShareButton />
149
            </div>
150
            <div className="px-2 pb-2">
151
              <FeedCommentSection
5608 stevensc 152
                isShow={showComments}
5607 stevensc 153
                currentComments={comments}
154
                addUrl={post.comments_add_url}
155
              />
156
            </div>
157
          </div>
5449 stevensc 158
        </div>
5607 stevensc 159
        <div className="col-12 col-md-4 p-0">
160
          <HomeNews currentPost={post.uuid} />
161
        </div>
162
      </div>
163
    </div>
5118 stevensc 164
  )
1 www 165
}