Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
2190 stevensc 1
import React, { useState } from 'react'
2
import { useSelector } from 'react-redux'
3
import { SendOutlined, ChatOutlined } from '@mui/icons-material'
4
 
5
import withExternalShare from '../dashboard/linkedin/withExternalShare'
6
import withReactions from '@app/hocs/withReaction'
7
 
8
import Button from '../UI/buttons/Buttons'
9
import Paraphrase from '../UI/Paraphrase'
10
import PostFile from './PostFile'
11
import FeedReactions from '../dashboard/linkedin/feed/FeedReactions'
2245 stevensc 12
 
2190 stevensc 13
import CommentForm from '../dashboard/linkedin/comments/comment-form'
14
import CommentsList from '../dashboard/linkedin/comments/comment-list'
2377 stevensc 15
import Widget from '../UI/Widget'
2190 stevensc 16
 
17
function PostCard({
18
  post,
19
  addComment,
20
  updateReactions,
21
  updateMyReaction,
22
  updateTotalShare
23
}) {
24
  const {
25
    reactions,
26
    my_reaction,
27
    reactions_url,
28
    save_reaction_url,
29
    delete_reaction_url,
30
    total_share_external,
31
    image,
32
    title,
33
    description,
34
    file,
35
    type,
36
    comments,
37
    share_external_url,
38
    share_increment_external_counter_url
39
  } = post
40
  const [showComments, setShowComments] = useState(false)
41
  const labels = useSelector(({ intl }) => intl.labels)
42
 
43
  const displayCommentSection = () => {
44
    setShowComments(!showComments)
45
  }
46
 
2245 stevensc 47
  const ExternalShareButton = withExternalShare(Button, share_external_url)
2190 stevensc 48
 
49
  const ReactionButton = withReactions(Button)
50
 
51
  return (
2377 stevensc 52
    <Widget>
53
      <Widget.Media
2190 stevensc 54
        src={image}
2377 stevensc 55
        alt={title}
56
        styles={{
2190 stevensc 57
          width: '100%',
58
          maxHeight: '450px',
59
          objectFit: 'contain'
60
        }}
61
      />
2377 stevensc 62
 
63
      <Widget.Body>
2190 stevensc 64
        <h2>{title}</h2>
65
        <Paraphrase>{description}</Paraphrase>
66
        <PostFile file={file} type={type} />
2377 stevensc 67
      </Widget.Body>
2190 stevensc 68
 
69
      <div className='d-flex justify-content-between align-items-center px-3'>
70
        <FeedReactions reactions={reactions} reactionsUrl={reactions_url} />
71
 
72
        {!!total_share_external && (
73
          <span>{`${total_share_external} ${labels.sends?.toLowerCase()}`}</span>
74
        )}
75
      </div>
76
 
2377 stevensc 77
      <Widget.Actions>
2190 stevensc 78
        <ReactionButton
79
          currentReactionType={my_reaction}
80
          saveUrl={save_reaction_url}
81
          deleteUrl={delete_reaction_url}
82
          onReaction={({ reactions }, currentReaction) => {
83
            updateReactions(reactions)
84
            updateMyReaction(currentReaction)
85
          }}
86
        />
87
 
88
        <Button onClick={displayCommentSection}>
89
          <ChatOutlined style={{ color: 'gray' }} />
90
          {labels.comment}
91
        </Button>
92
 
2245 stevensc 93
        <ExternalShareButton
94
          shorterUrl={share_increment_external_counter_url}
95
          setValue={updateTotalShare}
96
        >
97
          <SendOutlined style={{ color: 'gray' }} />
98
          {labels.send}
99
        </ExternalShareButton>
2377 stevensc 100
      </Widget.Actions>
2190 stevensc 101
 
102
      {showComments && (
103
        <div className='px-3 pb-2'>
104
          <CommentForm onSubmit={addComment} />
105
          <CommentsList comments={comments} />
106
        </div>
107
      )}
2377 stevensc 108
    </Widget>
2190 stevensc 109
  )
110
}
111
 
112
export default PostCard