Proyectos de Subversion LeadersLinked - SPA

Rev

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