Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7112 | Rev 7118 | 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'
5812 stevensc 3
import parse from 'html-react-parser'
4817 stevensc 4
import { axios } from '../../utils'
5812 stevensc 5
import { useDispatch } from 'react-redux'
6
import { setIntlLabels } from '../../redux/intl/intl.action'
5814 stevensc 7
import withReactions from '../components/feed/withReaction'
4817 stevensc 8
import { addNotification } from '../../redux/notification/notification.actions'
4816 stevensc 9
 
4817 stevensc 10
import HomeNews from '../components/home-section/HomeNews'
11
import InputOption from '../templates/linkedin/Feed/InputOption'
12
import withExternalShare from '../templates/linkedin/Feed/withExternalShare'
5812 stevensc 13
import FeedCommentSection from '../components/feed/feed-comment/FeedCommentSection'
3361 stevensc 14
 
4816 stevensc 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'
5812 stevensc 18
import RecommendIcon from '@mui/icons-material/Recommend'
19
import FavoriteIcon from '@mui/icons-material/FavoriteTwoTone'
20
import VolunteerActivismIcon from '@mui/icons-material/VolunteerActivism'
21
import EmojiEmotionsIcon from '@mui/icons-material/EmojiEmotions'
22
import TungstenIcon from '@mui/icons-material/Tungsten'
3361 stevensc 23
 
4817 stevensc 24
import '../templates/linkedin/Feed/Feed.scss'
25
 
5617 stevensc 26
export default function PostView({ post, labels }) {
5118 stevensc 27
  const [externalShare, setExternalShare] = useState(post.total_share_external)
5812 stevensc 28
  const [ownerReactions, setOwnerReaction] = useState(post.reactions)
5818 stevensc 29
  const [currentReaction, setCurrentReaction] = useState(post.my_reaction)
5812 stevensc 30
  const [totalReactions, setTotalReactions] = useState(0)
5118 stevensc 31
  const [comments, setComments] = useState([])
32
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
33
  const [showComments, setShowComments] = useState(false)
5617 stevensc 34
  const dispatch = useDispatch()
3810 stevensc 35
 
5812 stevensc 36
  const reactionsOptions = [
37
    {
38
      type: 'r',
39
      icon: <RecommendIcon style={{ color: '#7405f9' }} />,
40
    },
41
    {
42
      type: 's',
43
      icon: <VolunteerActivismIcon style={{ color: '#6495ED' }} />,
44
    },
45
    {
46
      type: 'l',
47
      icon: <FavoriteIcon style={{ color: '#DF704D' }} />,
48
    },
49
    {
50
      type: 'i',
51
      icon: (
52
        <TungstenIcon
53
          style={{ color: '#F5BB5C', transform: 'rotate(180deg)' }}
54
        />
55
      ),
56
    },
57
    {
58
      type: 'f',
59
      icon: <EmojiEmotionsIcon style={{ color: '#FF7F50' }} />,
60
    },
61
  ]
62
 
5118 stevensc 63
  const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
4816 stevensc 64
 
5118 stevensc 65
  const displayCommentSection = () => {
66
    setShowComments(!showComments)
67
  }
4821 stevensc 68
 
5118 stevensc 69
  const getComments = async () => {
5607 stevensc 70
    await axios.get(post.comments_url).then(({ data: response }) => {
71
      if (!response.success) {
72
        addNotification({ style: 'danger', msg: response.data })
73
        return
74
      }
4818 stevensc 75
 
5607 stevensc 76
      setComments(response.data)
77
    })
5118 stevensc 78
  }
4816 stevensc 79
 
5118 stevensc 80
  const handleExternalShare = (value) => setExternalShare(value)
4816 stevensc 81
 
5607 stevensc 82
  const ExternalShareButton = withExternalShare(
83
    InputOption,
84
    post.share_external_url,
85
    {
86
      Icon: SendOutlinedIcon,
87
      color: 'gray',
88
      title: 'Enviar',
89
      shareUrl: post.share_increment_external_counter_url,
90
      setValue: handleExternalShare,
6018 stevensc 91
      withTitle: true,
5607 stevensc 92
    }
93
  )
4816 stevensc 94
 
5118 stevensc 95
  const htmlParsedText = (fullStringText) => {
96
    const fullText = parse(fullStringText)
97
    if (fullStringText.length > 500) {
98
      const shortenedString = fullStringText.substr(0, 500)
99
      const shortenedText = parse(`${shortenedString}... `)
100
      return (
5607 stevensc 101
        <>
102
          {isReadMoreActive ? fullText : shortenedText}
103
          <span className="cursor-pointer" onClick={readMoreHandler}>
104
            {isReadMoreActive ? ' Leer menos' : ' Leer más'}
105
          </span>
106
        </>
5118 stevensc 107
      )
4816 stevensc 108
    }
5118 stevensc 109
    return <p>{fullText}</p>
110
  }
3361 stevensc 111
 
5818 stevensc 112
  const saveReaction = (type) => {
5812 stevensc 113
    const reactionTypesUrl = {
114
      r: post.save_reaction_recommended_url,
115
      s: post.save_reaction_support_url,
116
      l: post.save_reaction_love_url,
117
      i: post.save_reaction_interest_url,
118
      f: post.save_reaction_fun_url,
119
    }
120
 
5818 stevensc 121
    axios.post(reactionTypesUrl[type]).then((res) => {
5812 stevensc 122
      const { success, data } = res.data
123
 
124
      if (!success) {
125
        dispatch(addNotification({ style: 'danger', msg: data }))
126
      }
127
 
128
      setOwnerReaction(data.reactions)
5818 stevensc 129
      setCurrentReaction(type)
5812 stevensc 130
    })
131
  }
132
 
5818 stevensc 133
  const deleteReaction = () => {
134
    axios.post(post.delete_reaction_url).then((res) => {
5812 stevensc 135
      const { success, data } = res.data
136
 
137
      if (!success) {
138
        dispatch(addNotification({ style: 'danger', msg: data }))
139
        return
140
      }
141
 
142
      setOwnerReaction(data.reactions)
5818 stevensc 143
      setCurrentReaction('')
5812 stevensc 144
    })
145
  }
146
 
5814 stevensc 147
  const WithReactionIcon = withReactions(InputOption, {
148
    onSelect: saveReaction,
149
    onDelete: deleteReaction,
5818 stevensc 150
    myReaction: currentReaction,
6017 stevensc 151
    withTitle: true,
5814 stevensc 152
  })
153
 
5118 stevensc 154
  useEffect(() => {
7113 stevensc 155
    axios
156
      .get(window.location.href, {
157
        headers: {
158
          'Content-Type': 'application/json',
159
        },
160
      })
161
      .then((response) => console.log(response.data))
5617 stevensc 162
    dispatch(setIntlLabels(labels))
163
  }, [])
164
 
165
  useEffect(() => {
5118 stevensc 166
    if (showComments && !comments.length) getComments()
167
  }, [showComments])
4821 stevensc 168
 
5812 stevensc 169
  useEffect(() => {
170
    const feedReactions = ownerReactions.reduce(
171
      (acc, reaction) => acc + Number(reaction.total),
172
 
173
    )
174
    setTotalReactions(feedReactions)
175
  }, [ownerReactions])
176
 
5118 stevensc 177
  return (
5607 stevensc 178
    <div className="container">
179
      <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
180
        <div className="col-12 col-md-8 p-0">
181
          <div className="feed">
5821 stevensc 182
            <div className="feed__body">
5607 stevensc 183
              {post.image && (
184
                <img
185
                  src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`}
186
                  className="Entradas"
187
                  loading="lazy"
188
                />
189
              )}
190
            </div>
5821 stevensc 191
            <div className="feed__body">
5820 stevensc 192
              <div className="feed__header">
5821 stevensc 193
                <div className="feed__info">
5607 stevensc 194
                  <h2>{post.title}</h2>
195
                  <div className="time__elapse">
196
                    <p>{post.addedOn}</p>
197
                    <AccessTimeIcon className="time__elapse-icon" />
198
                  </div>
1 www 199
                </div>
5607 stevensc 200
              </div>
201
              {post.description && htmlParsedText(post.description)}
7112 stevensc 202
              {post.file && (
203
                <a href={post.file} download>
204
                  <img
205
                    className="pdf"
206
                    src="/images/extension/pdf.png"
207
                    alt="pdf"
208
                  />
209
                </a>
210
              )}
4093 stevensc 211
            </div>
6016 stevensc 212
            <div className="d-flex justify-content-between align-items-center px-3">
5819 stevensc 213
              <div className="reactions-counter">
214
                {reactionsOptions
215
                  .filter((option) =>
216
                    ownerReactions.find(
217
                      (reaction) => reaction.reaction === option.type
218
                    )
5812 stevensc 219
                  )
5819 stevensc 220
                  .map((reaction) => reaction.icon)}
221
                <span>{totalReactions} reacciones</span>
222
              </div>
5813 stevensc 223
              {externalShare && (
6457 stevensc 224
                <span>{`${externalShare} ${labels.SENDS?.toLowerCase()}`}</span>
5813 stevensc 225
              )}
5812 stevensc 226
            </div>
5813 stevensc 227
            <div className="feed__buttons">
5814 stevensc 228
              <WithReactionIcon />
5607 stevensc 229
              <InputOption
230
                Icon={ChatOutlinedIcon}
5812 stevensc 231
                title={labels.COMMENTS}
5607 stevensc 232
                color="gray"
233
                onClick={displayCommentSection}
6017 stevensc 234
                withTitle
5607 stevensc 235
              />
236
              <ExternalShareButton />
237
            </div>
238
            <div className="px-2 pb-2">
239
              <FeedCommentSection
5608 stevensc 240
                isShow={showComments}
5607 stevensc 241
                currentComments={comments}
242
                addUrl={post.comments_add_url}
243
              />
244
            </div>
245
          </div>
5449 stevensc 246
        </div>
5607 stevensc 247
        <div className="col-12 col-md-4 p-0">
248
          <HomeNews currentPost={post.uuid} />
249
        </div>
250
      </div>
251
    </div>
5118 stevensc 252
  )
1 www 253
}