Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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