Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5607 | Rev 5617 | 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'
4817 stevensc 22
 
5607 stevensc 23
export default function PostView({
5118 stevensc 24
  post = {
25
    url: '',
5607 stevensc 26
    file: '',
27
    comments_url: '',
28
    comments_add_url: '',
29
  },
4816 stevensc 30
}) {
5118 stevensc 31
  const [isLiked, setIsLiked] = useState(post.is_liked)
32
  const [externalShare, setExternalShare] = useState(post.total_share_external)
33
  const [comments, setComments] = useState([])
34
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
35
  const [showComments, setShowComments] = useState(false)
3810 stevensc 36
 
5118 stevensc 37
  const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
4816 stevensc 38
 
5118 stevensc 39
  const displayCommentSection = () => {
40
    setShowComments(!showComments)
41
  }
4821 stevensc 42
 
5118 stevensc 43
  const getComments = async () => {
5607 stevensc 44
    await axios.get(post.comments_url).then(({ data: response }) => {
45
      if (!response.success) {
46
        addNotification({ style: 'danger', msg: response.data })
47
        return
48
      }
4818 stevensc 49
 
5607 stevensc 50
      setComments(response.data)
51
    })
5118 stevensc 52
  }
4816 stevensc 53
 
5118 stevensc 54
  const handleExternalShare = (value) => setExternalShare(value)
4816 stevensc 55
 
5607 stevensc 56
  const ExternalShareButton = withExternalShare(
57
    InputOption,
58
    post.share_external_url,
59
    {
60
      Icon: SendOutlinedIcon,
61
      color: 'gray',
62
      title: 'Enviar',
63
      shareUrl: post.share_increment_external_counter_url,
64
      setValue: handleExternalShare,
65
    }
66
  )
4816 stevensc 67
 
5118 stevensc 68
  const handleLike = (url) => {
5607 stevensc 69
    axios.post(url).then(({ data: response }) => {
70
      if (!response.success) {
71
        addNotification({ style: 'danger', msg: response.data })
72
        return
73
      }
74
      setIsLiked(!isLiked)
75
    })
5118 stevensc 76
  }
3810 stevensc 77
 
5118 stevensc 78
  const htmlParsedText = (fullStringText) => {
79
    const fullText = parse(fullStringText)
80
    if (fullStringText.length > 500) {
81
      const shortenedString = fullStringText.substr(0, 500)
82
      const shortenedText = parse(`${shortenedString}... `)
83
      return (
5607 stevensc 84
        <>
85
          {isReadMoreActive ? fullText : shortenedText}
86
          <span className="cursor-pointer" onClick={readMoreHandler}>
87
            {isReadMoreActive ? ' Leer menos' : ' Leer más'}
88
          </span>
89
        </>
5118 stevensc 90
      )
4816 stevensc 91
    }
5118 stevensc 92
    return <p>{fullText}</p>
93
  }
3361 stevensc 94
 
5118 stevensc 95
  useEffect(() => {
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
}