Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2885 | Rev 3694 | 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'
2864 stevensc 3
import { Box, Typography } from '@mui/material'
2190 stevensc 4
import { SendOutlined, ChatOutlined } from '@mui/icons-material'
5
 
2864 stevensc 6
import { parse } from '@utils'
2885 stevensc 7
import { withReactions } from '@hocs'
8
import withExternalShare from '@components/dashboard/linkedin/withExternalShare'
2864 stevensc 9
 
2885 stevensc 10
import Button from '@components/UI/buttons/Buttons'
2190 stevensc 11
import CommentForm from '../dashboard/linkedin/comments/comment-form'
12
import CommentsList from '../dashboard/linkedin/comments/comment-list'
2377 stevensc 13
import Widget from '../UI/Widget'
2885 stevensc 14
import PostFile from './PostFile'
2899 stevensc 15
import Reactions from '@components/dashboard/reactions/reactions'
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>
2393 stevensc 53
      <Widget.Media src={image} alt={title} height={450} />
2377 stevensc 54
 
55
      <Widget.Body>
2190 stevensc 56
        <h2>{title}</h2>
2381 stevensc 57
 
2864 stevensc 58
        <Typography>{parse(description)}</Typography>
2381 stevensc 59
 
2190 stevensc 60
        <PostFile file={file} type={type} />
2377 stevensc 61
      </Widget.Body>
2190 stevensc 62
 
2381 stevensc 63
      <Box
64
        sx={{
65
          display: 'flex',
66
          justifyContent: 'space-between',
67
          alignItems: 'center',
68
          padding: '0 0.5rem'
69
        }}
70
      >
2899 stevensc 71
        <Reactions reactions={reactions} reactionsUrl={reactions_url} />
2190 stevensc 72
 
2381 stevensc 73
        {total_share_external ? (
2190 stevensc 74
          <span>{`${total_share_external} ${labels.sends?.toLowerCase()}`}</span>
2381 stevensc 75
        ) : null}
76
      </Box>
2190 stevensc 77
 
2377 stevensc 78
      <Widget.Actions>
2190 stevensc 79
        <ReactionButton
80
          currentReactionType={my_reaction}
81
          saveUrl={save_reaction_url}
82
          deleteUrl={delete_reaction_url}
83
          onReaction={({ reactions }, currentReaction) => {
84
            updateReactions(reactions)
85
            updateMyReaction(currentReaction)
86
          }}
87
        />
88
 
89
        <Button onClick={displayCommentSection}>
90
          <ChatOutlined style={{ color: 'gray' }} />
91
          {labels.comment}
92
        </Button>
93
 
2245 stevensc 94
        <ExternalShareButton
95
          shorterUrl={share_increment_external_counter_url}
96
          setValue={updateTotalShare}
97
        >
98
          <SendOutlined style={{ color: 'gray' }} />
99
          {labels.send}
100
        </ExternalShareButton>
2377 stevensc 101
      </Widget.Actions>
2190 stevensc 102
 
2381 stevensc 103
      {showComments ? (
104
        <Box
105
          sx={{
106
            padding: '0.5rem'
107
          }}
108
        >
2190 stevensc 109
          <CommentForm onSubmit={addComment} />
110
          <CommentsList comments={comments} />
2381 stevensc 111
        </Box>
112
      ) : null}
2377 stevensc 113
    </Widget>
2190 stevensc 114
  )
115
}
116
 
117
export default PostCard