Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
4265 stevensc 1
/* eslint-disable react/prop-types */
4280 stevensc 2
import React, { useState } from 'react'
4265 stevensc 3
import ThumbUpAltOutlinedIcon from '@mui/icons-material/ThumbUpAltOutlined'
4280 stevensc 4
import ThumbUpAltIcon from '@mui/icons-material/ThumbUpAlt'
4265 stevensc 5
import ChatOutlinedIcon from '@mui/icons-material/ChatOutlined'
6
import ShareOutlinedIcon from '@mui/icons-material/ShareOutlined'
7
import SendOutlinedIcon from '@mui/icons-material/SendOutlined'
8
import InputOption from './InputOption'
4270 stevensc 9
import parse from 'html-react-parser'
4265 stevensc 10
import Avatar from '../../../../shared/Avatar/Avatar'
4271 stevensc 11
import AccessTimeIcon from '@mui/icons-material/AccessTime';
4280 stevensc 12
import { axios } from '../../../../utils'
13
import { addNotification } from '../../../../redux/notification/notification.actions'
14
import { openShareModal } from '../../../../redux/share-modal/shareModal.actions'
15
import { shareModalTypes } from '../../../../redux/share-modal/shareModal.types'
16
import { feedTypes } from '../../../../redux/feed/feed.types'
17
import FeedCommentSection from '../../../components/feed/feed-comment/FeedCommentSection'
4281 stevensc 18
import { connect } from 'react-redux'
4285 stevensc 19
import withReactionList from './withReactionList'
4265 stevensc 20
 
4271 stevensc 21
const Feed = ({
4280 stevensc 22
  feed_unique,
4271 stevensc 23
  feed_is_liked,
24
  feed_like_url,
25
  feed_unlike_url,
26
  feed_share_url,
27
  feed_share_external_url,
28
  feed_delete_url,
29
  feed_likes,
30
  owner_url,
31
  owner_image,
32
  owner_name,
33
  owner_description,
34
  owner_shared,
35
  owner_comments,
36
  owner_time_elapse,
37
  owner_file_image_preview,
38
  owner_file_video,
39
  owner_file_image,
40
  owner_file_document,
41
  comment_add_url,
4282 stevensc 42
  comments,
43
  addNotification, // REDUX ACTION
44
  openShareModal, // REDUX ACTION
4271 stevensc 45
}) => {
4265 stevensc 46
 
4280 stevensc 47
  const [feedIsLiked, setFeedIsLiked] = useState(feed_is_liked);
48
  const [likesState, setLikesState] = useState(feed_likes);
49
  const [totalComments, setTotalComments] = useState(owner_comments);
50
  const [sharedState, setSharedState] = useState(owner_shared);
51
  const [showComments, setShowComments] = useState(false);
4271 stevensc 52
 
4280 stevensc 53
  const handleLike = (url) => {
54
    axios.post(url)
55
      .then(({ data: response }) => {
56
        if (!response.success) {
57
          addNotification({ style: "danger", msg: response.data })
58
          return
59
        }
60
        setLikesState(response.data.likes)
61
        setFeedIsLiked(!feedIsLiked);
62
      });
63
  };
4278 stevensc 64
 
4280 stevensc 65
  const handleShare = () => openShareModal(feed_share_url, shareModalTypes.SHARE, feedTypes.DASHBOARD, feed_unique)
4271 stevensc 66
 
4280 stevensc 67
  const displayCommentSection = () => setShowComments(!showComments)
4265 stevensc 68
 
4290 stevensc 69
  const ExternalShareButton = withReactionList(InputOption, feed_share_external_url, SendOutlinedIcon)
4285 stevensc 70
 
4280 stevensc 71
  return (
72
    <div className='feed'>
73
 
74
      <Feed.Header
75
        image={owner_image}
76
        name={owner_name}
77
        timeElapsed={owner_time_elapse}
4284 stevensc 78
        deleteUrl={feed_delete_url}
4280 stevensc 79
      />
80
 
4265 stevensc 81
      <div className='feed__body'>
4280 stevensc 82
        <Feed.Content
83
          ownerDescription={owner_description}
84
          ownerFileImage={owner_file_image}
85
          ownerFileImagepreview={owner_file_image_preview}
86
          ownerFileVideo={owner_file_video}
87
          ownerFileDocument={owner_file_document}
88
        />
4265 stevensc 89
      </div>
90
 
91
      <div className='feed__buttons'>
4280 stevensc 92
        <InputOption
93
          Icon={feedIsLiked ? ThumbUpAltIcon : ThumbUpAltOutlinedIcon}
94
          title='Like'
95
          color={feedIsLiked ? '#7405f9' : 'gray'}
4281 stevensc 96
          onClick={() => handleLike(feedIsLiked ? feed_unlike_url : feed_like_url)}
4280 stevensc 97
        />
98
        <InputOption
99
          Icon={ChatOutlinedIcon}
100
          title='Comment'
101
          color='gray'
102
          onClick={displayCommentSection}
103
        />
104
        <InputOption
105
          Icon={ShareOutlinedIcon}
106
          title='Share'
107
          color='gray'
108
          onClick={handleShare}
109
        />
4285 stevensc 110
        <ExternalShareButton />
4265 stevensc 111
      </div>
112
 
4280 stevensc 113
      <FeedCommentSection
114
        feedId={feed_unique}
115
        image={owner_image}
116
        addUrl={comment_add_url}
117
        updateTotalComments={(total) => setTotalComments(total)}
118
        comments={comments}
119
        isShow={showComments}
120
      />
121
 
4265 stevensc 122
    </div>
123
  )
124
}
125
 
4280 stevensc 126
const Content = ({
127
  ownerDescription,
128
  ownerFileImage,
129
  ownerFileImagepreview,
130
  ownerFileVideo,
131
  ownerFileDocument
132
}) => {
133
  return (
134
    <>
135
      <p>{parse(ownerDescription)}</p>
136
      {ownerFileImage &&
137
        <img src={ownerFileImage} className="Entradas" loading='lazy' />
138
      }
139
      {ownerFileVideo &&
140
        <video
141
          src={ownerFileVideo}
142
          controls
143
          poster={ownerFileImagepreview}
144
          preload="none"
145
        />
146
      }
147
      {ownerFileDocument &&
148
        <a href={ownerFileDocument} target="_blank" rel="noreferrer">
149
          Descargar
150
        </a>
151
      }
152
    </>
153
  )
154
}
155
 
156
const Header = ({
4284 stevensc 157
  image = '',
158
  name = '',
159
  timeElapsed = '',
160
  deleteUrl = ''
4280 stevensc 161
}) => {
162
  return (
163
    <div className='feed__header'>
164
      <Avatar
165
        imageUrl={image}
166
        name={name}
167
        size='xl'
168
      />
169
      <div className='feed__info'>
170
        <h2>{name}</h2>
171
        <div className='time__elapse'>
172
          <p>
173
            {timeElapsed}
174
          </p>
175
          <AccessTimeIcon className='time__elapse-icon' />
176
        </div>
177
      </div>
178
    </div>
179
  )
180
}
181
 
182
Feed.Content = Content
183
Feed.Header = Header
184
 
4281 stevensc 185
const mapDispatchToProps = {
186
  addNotification: (notification) => addNotification(notification),
4282 stevensc 187
  openShareModal: (postUrl, modalType, feedType) => openShareModal(postUrl, modalType, feedType),
4281 stevensc 188
};
189
 
190
export default connect(null, mapDispatchToProps)(Feed)