Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3694 | | Comparar con el anterior | Ultima modificación | Ver Log |

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