Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7113 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4821 stevensc 1
import React, { useEffect, useState } from 'react'
5812 stevensc 2
import parse from 'html-react-parser'
4817 stevensc 3
import { axios } from '../../utils'
5812 stevensc 4
import { useDispatch } from 'react-redux'
5
import { setIntlLabels } from '../../redux/intl/intl.action'
5814 stevensc 6
import withReactions from '../components/feed/withReaction'
4817 stevensc 7
import { addNotification } from '../../redux/notification/notification.actions'
4816 stevensc 8
 
4817 stevensc 9
import HomeNews from '../components/home-section/HomeNews'
10
import InputOption from '../templates/linkedin/Feed/InputOption'
11
import withExternalShare from '../templates/linkedin/Feed/withExternalShare'
5812 stevensc 12
import FeedCommentSection from '../components/feed/feed-comment/FeedCommentSection'
3361 stevensc 13
 
4816 stevensc 14
import ChatOutlinedIcon from '@mui/icons-material/ChatOutlined'
15
import SendOutlinedIcon from '@mui/icons-material/SendOutlined'
4817 stevensc 16
import AccessTimeIcon from '@mui/icons-material/AccessTime'
5812 stevensc 17
import RecommendIcon from '@mui/icons-material/Recommend'
18
import FavoriteIcon from '@mui/icons-material/FavoriteTwoTone'
19
import VolunteerActivismIcon from '@mui/icons-material/VolunteerActivism'
20
import EmojiEmotionsIcon from '@mui/icons-material/EmojiEmotions'
21
import TungstenIcon from '@mui/icons-material/Tungsten'
3361 stevensc 22
 
4817 stevensc 23
import '../templates/linkedin/Feed/Feed.scss'
24
 
5617 stevensc 25
export default function PostView({ post, labels }) {
5118 stevensc 26
  const [externalShare, setExternalShare] = useState(post.total_share_external)
5812 stevensc 27
  const [ownerReactions, setOwnerReaction] = useState(post.reactions)
5818 stevensc 28
  const [currentReaction, setCurrentReaction] = useState(post.my_reaction)
5812 stevensc 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,
6018 stevensc 90
      withTitle: true,
5607 stevensc 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) => {
7118 stevensc 112
    axios.post(post.save_reaction_url).then((res) => {
5812 stevensc 113
      const { success, data } = res.data
114
 
115
      if (!success) {
116
        dispatch(addNotification({ style: 'danger', msg: data }))
117
      }
118
 
119
      setOwnerReaction(data.reactions)
5818 stevensc 120
      setCurrentReaction(type)
5812 stevensc 121
    })
122
  }
123
 
5818 stevensc 124
  const deleteReaction = () => {
125
    axios.post(post.delete_reaction_url).then((res) => {
5812 stevensc 126
      const { success, data } = res.data
127
 
128
      if (!success) {
129
        dispatch(addNotification({ style: 'danger', msg: data }))
130
        return
131
      }
132
 
133
      setOwnerReaction(data.reactions)
5818 stevensc 134
      setCurrentReaction('')
5812 stevensc 135
    })
136
  }
137
 
5814 stevensc 138
  const WithReactionIcon = withReactions(InputOption, {
139
    onSelect: saveReaction,
140
    onDelete: deleteReaction,
5818 stevensc 141
    myReaction: currentReaction,
6017 stevensc 142
    withTitle: true,
5814 stevensc 143
  })
144
 
5118 stevensc 145
  useEffect(() => {
7113 stevensc 146
    axios
147
      .get(window.location.href, {
148
        headers: {
149
          'Content-Type': 'application/json',
150
        },
151
      })
152
      .then((response) => console.log(response.data))
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)}
7112 stevensc 193
              {post.file && (
194
                <a href={post.file} download>
195
                  <img
196
                    className="pdf"
197
                    src="/images/extension/pdf.png"
198
                    alt="pdf"
199
                  />
200
                </a>
201
              )}
4093 stevensc 202
            </div>
6016 stevensc 203
            <div className="d-flex justify-content-between align-items-center px-3">
5819 stevensc 204
              <div className="reactions-counter">
205
                {reactionsOptions
206
                  .filter((option) =>
207
                    ownerReactions.find(
208
                      (reaction) => reaction.reaction === option.type
209
                    )
5812 stevensc 210
                  )
5819 stevensc 211
                  .map((reaction) => reaction.icon)}
212
                <span>{totalReactions} reacciones</span>
213
              </div>
5813 stevensc 214
              {externalShare && (
6457 stevensc 215
                <span>{`${externalShare} ${labels.SENDS?.toLowerCase()}`}</span>
5813 stevensc 216
              )}
5812 stevensc 217
            </div>
5813 stevensc 218
            <div className="feed__buttons">
5814 stevensc 219
              <WithReactionIcon />
5607 stevensc 220
              <InputOption
221
                Icon={ChatOutlinedIcon}
5812 stevensc 222
                title={labels.COMMENTS}
5607 stevensc 223
                color="gray"
224
                onClick={displayCommentSection}
6017 stevensc 225
                withTitle
5607 stevensc 226
              />
227
              <ExternalShareButton />
228
            </div>
229
            <div className="px-2 pb-2">
230
              <FeedCommentSection
5608 stevensc 231
                isShow={showComments}
5607 stevensc 232
                currentComments={comments}
233
                addUrl={post.comments_add_url}
234
              />
235
            </div>
236
          </div>
5449 stevensc 237
        </div>
5607 stevensc 238
        <div className="col-12 col-md-4 p-0">
239
          <HomeNews currentPost={post.uuid} />
240
        </div>
241
      </div>
242
    </div>
5118 stevensc 243
  )
1 www 244
}