Proyectos de Subversion LeadersLinked - SPA

Rev

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