Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5820 | Rev 6016 | 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,
91
    }
92
  )
4816 stevensc 93
 
5118 stevensc 94
  const htmlParsedText = (fullStringText) => {
95
    const fullText = parse(fullStringText)
96
    if (fullStringText.length > 500) {
97
      const shortenedString = fullStringText.substr(0, 500)
98
      const shortenedText = parse(`${shortenedString}... `)
99
      return (
5607 stevensc 100
        <>
101
          {isReadMoreActive ? fullText : shortenedText}
102
          <span className="cursor-pointer" onClick={readMoreHandler}>
103
            {isReadMoreActive ? ' Leer menos' : ' Leer más'}
104
          </span>
105
        </>
5118 stevensc 106
      )
4816 stevensc 107
    }
5118 stevensc 108
    return <p>{fullText}</p>
109
  }
3361 stevensc 110
 
5818 stevensc 111
  const saveReaction = (type) => {
5812 stevensc 112
    const reactionTypesUrl = {
113
      r: post.save_reaction_recommended_url,
114
      s: post.save_reaction_support_url,
115
      l: post.save_reaction_love_url,
116
      i: post.save_reaction_interest_url,
117
      f: post.save_reaction_fun_url,
118
    }
119
 
5818 stevensc 120
    axios.post(reactionTypesUrl[type]).then((res) => {
5812 stevensc 121
      const { success, data } = res.data
122
 
123
      if (!success) {
124
        dispatch(addNotification({ style: 'danger', msg: data }))
125
      }
126
 
127
      setOwnerReaction(data.reactions)
5818 stevensc 128
      setCurrentReaction(type)
5812 stevensc 129
    })
130
  }
131
 
5818 stevensc 132
  const deleteReaction = () => {
133
    axios.post(post.delete_reaction_url).then((res) => {
5812 stevensc 134
      const { success, data } = res.data
135
 
136
      if (!success) {
137
        dispatch(addNotification({ style: 'danger', msg: data }))
138
        return
139
      }
140
 
141
      setOwnerReaction(data.reactions)
5818 stevensc 142
      setCurrentReaction('')
5812 stevensc 143
    })
144
  }
145
 
5814 stevensc 146
  const WithReactionIcon = withReactions(InputOption, {
147
    onSelect: saveReaction,
148
    onDelete: deleteReaction,
5818 stevensc 149
    myReaction: currentReaction,
5814 stevensc 150
  })
151
 
5118 stevensc 152
  useEffect(() => {
5617 stevensc 153
    dispatch(setIntlLabels(labels))
154
  }, [])
155
 
156
  useEffect(() => {
5118 stevensc 157
    if (showComments && !comments.length) getComments()
158
  }, [showComments])
4821 stevensc 159
 
5812 stevensc 160
  useEffect(() => {
161
    const feedReactions = ownerReactions.reduce(
162
      (acc, reaction) => acc + Number(reaction.total),
163
 
164
    )
165
    setTotalReactions(feedReactions)
166
  }, [ownerReactions])
167
 
5118 stevensc 168
  return (
5607 stevensc 169
    <div className="container">
170
      <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
171
        <div className="col-12 col-md-8 p-0">
172
          <div className="feed">
5821 stevensc 173
            <div className="feed__body">
5607 stevensc 174
              {post.image && (
175
                <img
176
                  src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`}
177
                  className="Entradas"
178
                  loading="lazy"
179
                />
180
              )}
181
            </div>
5821 stevensc 182
            <div className="feed__body">
5820 stevensc 183
              <div className="feed__header">
5821 stevensc 184
                <div className="feed__info">
5607 stevensc 185
                  <h2>{post.title}</h2>
186
                  <div className="time__elapse">
187
                    <p>{post.addedOn}</p>
188
                    <AccessTimeIcon className="time__elapse-icon" />
189
                  </div>
1 www 190
                </div>
5607 stevensc 191
              </div>
192
              {post.description && htmlParsedText(post.description)}
4093 stevensc 193
            </div>
5819 stevensc 194
            <div className="d-flex justify-content-between align-items-center">
195
              <div className="reactions-counter">
196
                {reactionsOptions
197
                  .filter((option) =>
198
                    ownerReactions.find(
199
                      (reaction) => reaction.reaction === option.type
200
                    )
5812 stevensc 201
                  )
5819 stevensc 202
                  .map((reaction) => reaction.icon)}
203
                <span>{totalReactions} reacciones</span>
204
              </div>
5813 stevensc 205
              {externalShare && (
206
                <span>{`${externalShare} ${labels.SENDS.toLowerCase()}`}</span>
207
              )}
5812 stevensc 208
            </div>
5813 stevensc 209
            <div className="feed__buttons">
5814 stevensc 210
              <WithReactionIcon />
5607 stevensc 211
              <InputOption
212
                Icon={ChatOutlinedIcon}
5812 stevensc 213
                title={labels.COMMENTS}
5607 stevensc 214
                color="gray"
215
                onClick={displayCommentSection}
216
              />
217
              <ExternalShareButton />
218
            </div>
219
            <div className="px-2 pb-2">
220
              <FeedCommentSection
5608 stevensc 221
                isShow={showComments}
5607 stevensc 222
                currentComments={comments}
223
                addUrl={post.comments_add_url}
224
              />
225
            </div>
226
          </div>
5449 stevensc 227
        </div>
5607 stevensc 228
        <div className="col-12 col-md-4 p-0">
229
          <HomeNews currentPost={post.uuid} />
230
        </div>
231
      </div>
232
    </div>
5118 stevensc 233
  )
1 www 234
}