Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2382 | Rev 2864 | 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>
2393 stevensc 54
      <Widget.Media src={image} alt={title} height={450} />
2377 stevensc 55
 
56
      <Widget.Body>
2190 stevensc 57
        <h2>{title}</h2>
2381 stevensc 58
 
2190 stevensc 59
        <Paraphrase>{description}</Paraphrase>
2381 stevensc 60
 
2190 stevensc 61
        <PostFile file={file} type={type} />
2377 stevensc 62
      </Widget.Body>
2190 stevensc 63
 
2381 stevensc 64
      <Box
65
        sx={{
66
          display: 'flex',
67
          justifyContent: 'space-between',
68
          alignItems: 'center',
69
          padding: '0 0.5rem'
70
        }}
71
      >
2190 stevensc 72
        <FeedReactions reactions={reactions} reactionsUrl={reactions_url} />
73
 
2381 stevensc 74
        {total_share_external ? (
2190 stevensc 75
          <span>{`${total_share_external} ${labels.sends?.toLowerCase()}`}</span>
2381 stevensc 76
        ) : null}
77
      </Box>
2190 stevensc 78
 
2377 stevensc 79
      <Widget.Actions>
2190 stevensc 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
 
2245 stevensc 95
        <ExternalShareButton
96
          shorterUrl={share_increment_external_counter_url}
97
          setValue={updateTotalShare}
98
        >
99
          <SendOutlined style={{ color: 'gray' }} />
100
          {labels.send}
101
        </ExternalShareButton>
2377 stevensc 102
      </Widget.Actions>
2190 stevensc 103
 
2381 stevensc 104
      {showComments ? (
105
        <Box
106
          sx={{
107
            padding: '0.5rem'
108
          }}
109
        >
2190 stevensc 110
          <CommentForm onSubmit={addComment} />
111
          <CommentsList comments={comments} />
2381 stevensc 112
        </Box>
113
      ) : null}
2377 stevensc 114
    </Widget>
2190 stevensc 115
  )
116
}
117
 
118
export default PostCard