Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2245 | Ir a la última revisión | | 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
import parse from 'html-react-parser'
5
 
6
import useMobile from '@app/hooks/useMobile'
7
import withExternalShare from '../dashboard/linkedin/withExternalShare'
8
import withReactions from '@app/hocs/withReaction'
9
 
10
import Button from '../UI/buttons/Buttons'
11
import WidgetWrapper from '../widgets/WidgetLayout'
12
import Paraphrase from '../UI/Paraphrase'
13
import PostFile from './PostFile'
14
import FeedReactions from '../dashboard/linkedin/feed/FeedReactions'
15
import MobileShare from '../dashboard/linkedin/mobile-share/MobileShare'
16
import CommentForm from '../dashboard/linkedin/comments/comment-form'
17
import CommentsList from '../dashboard/linkedin/comments/comment-list'
18
 
19
function PostCard({
20
  post,
21
  addComment,
22
  updateReactions,
23
  updateMyReaction,
24
  updateTotalShare
25
}) {
26
  const {
27
    reactions,
28
    my_reaction,
29
    reactions_url,
30
    save_reaction_url,
31
    delete_reaction_url,
32
    total_share_external,
33
    image,
34
    title,
35
    description,
36
    file,
37
    type,
38
    comments,
39
    share_external_url,
40
    share_increment_external_counter_url
41
  } = post
42
  const [showComments, setShowComments] = useState(false)
43
  const labels = useSelector(({ intl }) => intl.labels)
44
 
45
  const isMobile = useMobile()
46
 
47
  const displayCommentSection = () => {
48
    setShowComments(!showComments)
49
  }
50
 
51
  const ExternalShareButton = withExternalShare(Button, post.share_external_url)
52
 
53
  const ReactionButton = withReactions(Button)
54
 
55
  return (
56
    <WidgetWrapper>
57
      <img
58
        src={image}
59
        style={{
60
          width: '100%',
61
          maxHeight: '450px',
62
          objectFit: 'contain'
63
        }}
64
      />
65
      <WidgetWrapper.Body>
66
        <h2>{title}</h2>
67
        <Paraphrase>{description}</Paraphrase>
68
        <PostFile file={file} type={type} />
69
      </WidgetWrapper.Body>
70
 
71
      <div className='d-flex justify-content-between align-items-center px-3'>
72
        <FeedReactions reactions={reactions} reactionsUrl={reactions_url} />
73
 
74
        {!!total_share_external && (
75
          <span>{`${total_share_external} ${labels.sends?.toLowerCase()}`}</span>
76
        )}
77
      </div>
78
 
79
      <WidgetWrapper.Actions>
80
        <ReactionButton
81
          currentReactionType={my_reaction}
82
          saveUrl={save_reaction_url}
83
          deleteUrl={delete_reaction_url}
84
          onReaction={({ reactions }, currentReaction) => {
85
            updateReactions(reactions)
86
            updateMyReaction(currentReaction)
87
          }}
88
        />
89
 
90
        <Button onClick={displayCommentSection}>
91
          <ChatOutlined style={{ color: 'gray' }} />
92
          {labels.comment}
93
        </Button>
94
 
95
        {!isMobile ? (
96
          <ExternalShareButton
97
            shorterUrl={share_increment_external_counter_url}
98
            setValue={updateTotalShare}
99
          >
100
            <SendOutlined style={{ color: 'gray' }} />
101
            {labels.send}
102
          </ExternalShareButton>
103
        ) : (
104
          <MobileShare
105
            shareData={{
106
              title: 'Leaders Linked',
107
              text: parse(description ?? ''),
108
              url: share_external_url
109
            }}
110
          >
111
            <SendOutlined />
112
            {labels.send}
113
          </MobileShare>
114
        )}
115
      </WidgetWrapper.Actions>
116
 
117
      {showComments && (
118
        <div className='px-3 pb-2'>
119
          <CommentForm onSubmit={addComment} />
120
          <CommentsList comments={comments} />
121
        </div>
122
      )}
123
    </WidgetWrapper>
124
  )
125
}
126
 
127
export default PostCard