Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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