Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5617 | Rev 5813 | 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'
7
import { ReactionButton } 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)
29
  const [totalReactions, setTotalReactions] = useState(0)
5118 stevensc 30
  const [comments, setComments] = useState([])
31
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
32
  const [showComments, setShowComments] = useState(false)
5617 stevensc 33
  const dispatch = useDispatch()
3810 stevensc 34
 
5812 stevensc 35
  const reactionsOptions = [
36
    {
37
      type: 'r',
38
      icon: <RecommendIcon style={{ color: '#7405f9' }} />,
39
    },
40
    {
41
      type: 's',
42
      icon: <VolunteerActivismIcon style={{ color: '#6495ED' }} />,
43
    },
44
    {
45
      type: 'l',
46
      icon: <FavoriteIcon style={{ color: '#DF704D' }} />,
47
    },
48
    {
49
      type: 'i',
50
      icon: (
51
        <TungstenIcon
52
          style={{ color: '#F5BB5C', transform: 'rotate(180deg)' }}
53
        />
54
      ),
55
    },
56
    {
57
      type: 'f',
58
      icon: <EmojiEmotionsIcon style={{ color: '#FF7F50' }} />,
59
    },
60
  ]
61
 
5118 stevensc 62
  const readMoreHandler = () => setIsReadMoreActive(!isReadMoreActive)
4816 stevensc 63
 
5118 stevensc 64
  const displayCommentSection = () => {
65
    setShowComments(!showComments)
66
  }
4821 stevensc 67
 
5118 stevensc 68
  const getComments = async () => {
5607 stevensc 69
    await axios.get(post.comments_url).then(({ data: response }) => {
70
      if (!response.success) {
71
        addNotification({ style: 'danger', msg: response.data })
72
        return
73
      }
4818 stevensc 74
 
5607 stevensc 75
      setComments(response.data)
76
    })
5118 stevensc 77
  }
4816 stevensc 78
 
5118 stevensc 79
  const handleExternalShare = (value) => setExternalShare(value)
4816 stevensc 80
 
5607 stevensc 81
  const ExternalShareButton = withExternalShare(
82
    InputOption,
83
    post.share_external_url,
84
    {
85
      Icon: SendOutlinedIcon,
86
      color: 'gray',
87
      title: 'Enviar',
88
      shareUrl: post.share_increment_external_counter_url,
89
      setValue: handleExternalShare,
90
    }
91
  )
4816 stevensc 92
 
5118 stevensc 93
  const htmlParsedText = (fullStringText) => {
94
    const fullText = parse(fullStringText)
95
    if (fullStringText.length > 500) {
96
      const shortenedString = fullStringText.substr(0, 500)
97
      const shortenedText = parse(`${shortenedString}... `)
98
      return (
5607 stevensc 99
        <>
100
          {isReadMoreActive ? fullText : shortenedText}
101
          <span className="cursor-pointer" onClick={readMoreHandler}>
102
            {isReadMoreActive ? ' Leer menos' : ' Leer más'}
103
          </span>
104
        </>
5118 stevensc 105
      )
4816 stevensc 106
    }
5118 stevensc 107
    return <p>{fullText}</p>
108
  }
3361 stevensc 109
 
5812 stevensc 110
  const saveReaction = async (type) => {
111
    const reactionTypesUrl = {
112
      r: post.save_reaction_recommended_url,
113
      s: post.save_reaction_support_url,
114
      l: post.save_reaction_love_url,
115
      i: post.save_reaction_interest_url,
116
      f: post.save_reaction_fun_url,
117
    }
118
 
119
    await axios.post(reactionTypesUrl[type]).then((res) => {
120
      const { success, data } = res.data
121
 
122
      if (!success) {
123
        dispatch(addNotification({ style: 'danger', msg: data }))
124
      }
125
 
126
      setOwnerReaction(data.reactions)
127
      return true
128
    })
129
  }
130
 
131
  const deleteReaction = async () => {
132
    await axios.post(post.delete_reaction_url).then((res) => {
133
      const { success, data } = res.data
134
 
135
      if (!success) {
136
        dispatch(addNotification({ style: 'danger', msg: data }))
137
        return
138
      }
139
 
140
      setOwnerReaction(data.reactions)
141
      return true
142
    })
143
  }
144
 
5118 stevensc 145
  useEffect(() => {
5617 stevensc 146
    dispatch(setIntlLabels(labels))
147
  }, [])
148
 
149
  useEffect(() => {
5118 stevensc 150
    if (showComments && !comments.length) getComments()
151
  }, [showComments])
4821 stevensc 152
 
5812 stevensc 153
  useEffect(() => {
154
    const feedReactions = ownerReactions.reduce(
155
      (acc, reaction) => acc + Number(reaction.total),
156
 
157
    )
158
    setTotalReactions(feedReactions)
159
  }, [ownerReactions])
160
 
5118 stevensc 161
  return (
5607 stevensc 162
    <div className="container">
163
      <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
164
        <div className="col-12 col-md-8 p-0">
165
          <div className="feed">
5812 stevensc 166
            <div className="_body">
5607 stevensc 167
              {post.image && (
168
                <img
169
                  src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`}
170
                  className="Entradas"
171
                  loading="lazy"
172
                />
173
              )}
174
            </div>
5812 stevensc 175
            <div className="_body">
176
              <div className="_header">
177
                <div className="_info">
5607 stevensc 178
                  <h2>{post.title}</h2>
179
                  <div className="time__elapse">
180
                    <p>{post.addedOn}</p>
181
                    <AccessTimeIcon className="time__elapse-icon" />
182
                  </div>
1 www 183
                </div>
5607 stevensc 184
              </div>
185
              {post.description && htmlParsedText(post.description)}
4093 stevensc 186
            </div>
5607 stevensc 187
            <div
188
              className="px-3 d-flex align-items-center justify-content-end"
189
              style={{ gap: '5px' }}
190
            >
191
              {!!externalShare && (
5812 stevensc 192
                <span>{`${externalShare} ${labels.SENDS.toLowerCase()}`}</span>
5607 stevensc 193
              )}
194
            </div>
5812 stevensc 195
            <div className="reactions-counter">
196
              {reactionsOptions
197
                .filter((option) =>
198
                  ownerReactions.find(
199
                    (reaction) => reaction.reaction === option.type
200
                  )
201
                )
202
                .map((reaction) => reaction.icon)}
203
              <span>{totalReactions} reacciones</span>
204
            </div>
205
            <div className="_buttons">
206
              <ReactionButton
207
                onSelect={saveReaction}
208
                onDelete={deleteReaction}
209
                myReaction={post.my_reaction}
5607 stevensc 210
              />
5812 stevensc 211
 
5607 stevensc 212
              <InputOption
213
                Icon={ChatOutlinedIcon}
5812 stevensc 214
                title={labels.COMMENTS}
5607 stevensc 215
                color="gray"
216
                onClick={displayCommentSection}
217
              />
218
              <ExternalShareButton />
219
            </div>
220
            <div className="px-2 pb-2">
221
              <FeedCommentSection
5608 stevensc 222
                isShow={showComments}
5607 stevensc 223
                currentComments={comments}
224
                addUrl={post.comments_add_url}
225
              />
226
            </div>
227
          </div>
5449 stevensc 228
        </div>
5607 stevensc 229
        <div className="col-12 col-md-4 p-0">
230
          <HomeNews currentPost={post.uuid} />
231
        </div>
232
      </div>
233
    </div>
5118 stevensc 234
  )
1 www 235
}