Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5617 | Rev 5813 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5617 Rev 5812
Línea 1... Línea 1...
1
/* eslint-disable react/prop-types */
1
/* eslint-disable react/prop-types */
2
import React, { useEffect, useState } from 'react'
2
import React, { useEffect, useState } from 'react'
-
 
3
import parse from 'html-react-parser'
3
import { axios } from '../../utils'
4
import { axios } from '../../utils'
-
 
5
import { useDispatch } from 'react-redux'
-
 
6
import { setIntlLabels } from '../../redux/intl/intl.action'
-
 
7
import { ReactionButton } from '../components/feed/withReaction'
4
import { addNotification } from '../../redux/notification/notification.actions'
8
import { addNotification } from '../../redux/notification/notification.actions'
5
import parse from 'html-react-parser'
-
 
Línea 6... Línea -...
6
 
-
 
7
// Components
9
 
8
import HomeNews from '../components/home-section/HomeNews'
10
import HomeNews from '../components/home-section/HomeNews'
9
import InputOption from '../templates/linkedin/Feed/InputOption'
11
import InputOption from '../templates/linkedin/Feed/InputOption'
-
 
12
import withExternalShare from '../templates/linkedin/Feed/withExternalShare'
Línea 10... Línea -...
10
import withExternalShare from '../templates/linkedin/Feed/withExternalShare'
-
 
11
 
-
 
12
// Icons
-
 
13
import ThumbUpAltOutlinedIcon from '@mui/icons-material/ThumbUpAltOutlined'
13
import FeedCommentSection from '../components/feed/feed-comment/FeedCommentSection'
14
import ThumbUpAltIcon from '@mui/icons-material/ThumbUpAlt'
14
 
15
import ChatOutlinedIcon from '@mui/icons-material/ChatOutlined'
15
import ChatOutlinedIcon from '@mui/icons-material/ChatOutlined'
-
 
16
import SendOutlinedIcon from '@mui/icons-material/SendOutlined'
-
 
17
import AccessTimeIcon from '@mui/icons-material/AccessTime'
-
 
18
import RecommendIcon from '@mui/icons-material/Recommend'
-
 
19
import FavoriteIcon from '@mui/icons-material/FavoriteTwoTone'
-
 
20
import VolunteerActivismIcon from '@mui/icons-material/VolunteerActivism'
Línea 16... Línea -...
16
import SendOutlinedIcon from '@mui/icons-material/SendOutlined'
-
 
17
import AccessTimeIcon from '@mui/icons-material/AccessTime'
21
import EmojiEmotionsIcon from '@mui/icons-material/EmojiEmotions'
18
 
-
 
19
// Styles
-
 
20
import '../templates/linkedin/Feed/Feed.scss'
-
 
Línea 21... Línea 22...
21
import FeedCommentSection from '../components/feed/feed-comment/FeedCommentSection'
22
import TungstenIcon from '@mui/icons-material/Tungsten'
22
import { useDispatch } from 'react-redux'
-
 
23
import { setIntlLabels } from '../../redux/intl/intl.action'
23
 
-
 
24
import '../templates/linkedin/Feed/Feed.scss'
-
 
25
 
24
 
26
export default function PostView({ post, labels }) {
25
export default function PostView({ post, labels }) {
27
  const [externalShare, setExternalShare] = useState(post.total_share_external)
26
  const [isLiked, setIsLiked] = useState(post.is_liked)
28
  const [ownerReactions, setOwnerReaction] = useState(post.reactions)
27
  const [externalShare, setExternalShare] = useState(post.total_share_external)
29
  const [totalReactions, setTotalReactions] = useState(0)
Línea -... Línea 30...
-
 
30
  const [comments, setComments] = useState([])
-
 
31
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
-
 
32
  const [showComments, setShowComments] = useState(false)
-
 
33
  const dispatch = useDispatch()
-
 
34
 
-
 
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
    {
28
  const [comments, setComments] = useState([])
57
      type: 'f',
Línea 29... Línea 58...
29
  const [isReadMoreActive, setIsReadMoreActive] = useState(false)
58
      icon: <EmojiEmotionsIcon style={{ color: '#FF7F50' }} />,
30
  const [showComments, setShowComments] = useState(false)
59
    },
31
  const dispatch = useDispatch()
60
  ]
Línea 59... Línea 88...
59
      shareUrl: post.share_increment_external_counter_url,
88
      shareUrl: post.share_increment_external_counter_url,
60
      setValue: handleExternalShare,
89
      setValue: handleExternalShare,
61
    }
90
    }
62
  )
91
  )
Línea 63... Línea -...
63
 
-
 
64
  const handleLike = (url) => {
-
 
65
    axios.post(url).then(({ data: response }) => {
-
 
66
      if (!response.success) {
-
 
67
        addNotification({ style: 'danger', msg: response.data })
-
 
68
        return
-
 
69
      }
-
 
70
      setIsLiked(!isLiked)
-
 
71
    })
-
 
72
  }
-
 
73
 
92
 
74
  const htmlParsedText = (fullStringText) => {
93
  const htmlParsedText = (fullStringText) => {
75
    const fullText = parse(fullStringText)
94
    const fullText = parse(fullStringText)
76
    if (fullStringText.length > 500) {
95
    if (fullStringText.length > 500) {
77
      const shortenedString = fullStringText.substr(0, 500)
96
      const shortenedString = fullStringText.substr(0, 500)
Línea 86... Línea 105...
86
      )
105
      )
87
    }
106
    }
88
    return <p>{fullText}</p>
107
    return <p>{fullText}</p>
89
  }
108
  }
Línea -... Línea 109...
-
 
109
 
-
 
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
  }
90
 
144
 
91
  useEffect(() => {
145
  useEffect(() => {
92
    dispatch(setIntlLabels(labels))
146
    dispatch(setIntlLabels(labels))
Línea 93... Línea 147...
93
  }, [])
147
  }, [])
94
 
148
 
95
  useEffect(() => {
149
  useEffect(() => {
Línea -... Línea 150...
-
 
150
    if (showComments && !comments.length) getComments()
-
 
151
  }, [showComments])
-
 
152
 
-
 
153
  useEffect(() => {
-
 
154
    const feedReactions = ownerReactions.reduce(
-
 
155
      (acc, reaction) => acc + Number(reaction.total),
-
 
156
      0
-
 
157
    )
96
    if (showComments && !comments.length) getComments()
158
    setTotalReactions(feedReactions)
97
  }, [showComments])
159
  }, [ownerReactions])
98
 
160
 
99
  return (
161
  return (
100
    <div className="container">
162
    <div className="container">
101
      <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
163
      <div className="d-flex flex-column flex-md-row" style={{ gap: '1rem' }}>
102
        <div className="col-12 col-md-8 p-0">
164
        <div className="col-12 col-md-8 p-0">
103
          <div className="feed">
165
          <div className="feed">
104
            <div className="feed__body">
166
            <div className="_body">
105
              {post.image && (
167
              {post.image && (
106
                <img
168
                <img
107
                  src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`}
169
                  src={`/storage/type/post/code/${post.uuid}/filename/${post.image}`}
108
                  className="Entradas"
170
                  className="Entradas"
109
                  loading="lazy"
171
                  loading="lazy"
110
                />
172
                />
111
              )}
173
              )}
112
            </div>
174
            </div>
113
            <div className="feed__body">
175
            <div className="_body">
114
              <div className="feed__header">
176
              <div className="_header">
115
                <div className="feed__info">
177
                <div className="_info">
116
                  <h2>{post.title}</h2>
178
                  <h2>{post.title}</h2>
117
                  <div className="time__elapse">
179
                  <div className="time__elapse">
Línea 125... Línea 187...
125
            <div
187
            <div
126
              className="px-3 d-flex align-items-center justify-content-end"
188
              className="px-3 d-flex align-items-center justify-content-end"
127
              style={{ gap: '5px' }}
189
              style={{ gap: '5px' }}
128
            >
190
            >
129
              {!!externalShare && (
191
              {!!externalShare && (
130
                <span>{`${externalShare} ${LABELS.SENDS.toLowerCase()}`}</span>
192
                <span>{`${externalShare} ${labels.SENDS.toLowerCase()}`}</span>
131
              )}
193
              )}
132
            </div>
194
            </div>
133
            <div className="feed__buttons">
195
            <div className="reactions-counter">
134
              <InputOption
196
              {reactionsOptions
135
                Icon={isLiked ? ThumbUpAltIcon : ThumbUpAltOutlinedIcon}
197
                .filter((option) =>
136
                title={isLiked ? LABELS.UNLIKE : LABELS.LIKE}
198
                  ownerReactions.find(
137
                color={isLiked ? '#7405f9' : 'gray'}
199
                    (reaction) => reaction.reaction === option.type
138
                onClick={() =>
200
                  )
-
 
201
                )
139
                  handleLike(isLiked ? post.unlike_url : post.like_url)
202
                .map((reaction) => reaction.icon)}
-
 
203
              <span>{totalReactions} reacciones</span>
140
                }
204
            </div>
-
 
205
            <div className="_buttons">
-
 
206
              <ReactionButton
-
 
207
                onSelect={saveReaction}
-
 
208
                onDelete={deleteReaction}
-
 
209
                myReaction={post.my_reaction}
141
              />
210
              />
-
 
211
 
142
              <InputOption
212
              <InputOption
143
                Icon={ChatOutlinedIcon}
213
                Icon={ChatOutlinedIcon}
144
                title={LABELS.COMMENTS}
214
                title={labels.COMMENTS}
145
                color="gray"
215
                color="gray"
146
                onClick={displayCommentSection}
216
                onClick={displayCommentSection}
147
              />
217
              />
148
              <ExternalShareButton />
218
              <ExternalShareButton />
149
            </div>
219
            </div>