Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2899 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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