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 { useDispatch, useSelector } from 'react-redux';
3
import { Box, Button, styled, Typography } from '@mui/material';
4
import ChatOutlined from '@mui/icons-material/ChatOutlined';
5
import SendOutlined from '@mui/icons-material/SendOutlined';
6
import ShareOutlined from '@mui/icons-material/ShareOutlined';
7
 
8
import { withReactions } from '@hocs';
9
import { feedTypes } from '@store/feed/feed.types';
10
import { shareModalTypes } from '@store/share-modal/shareModal.types';
11
import { openShareModal } from '@store/share-modal/shareModal.actions';
12
 
13
import Widget from '@components/UI/Widget';
14
import Comments from '../linkedin/comments/comments';
15
import Reactions from '../reactions/reactions';
16
import withExternalShare from '../linkedin/withExternalShare';
17
 
18
const Row = styled(Box)(({ theme }) => ({
19
  display: 'flex',
20
  padding: theme.spacing(0.5),
21
  justifyContent: 'space-between',
22
  alignItems: 'center',
23
  gap: theme.spacing(0.5)
24
}));
25
 
26
export default function FeedActions({ id }) {
27
  const {
28
    comments,
29
    comment_add_url: commentAddUrl,
30
    owner_comments: ownerComments,
31
    feed_reactions_url: reactionsUrl,
32
    feed_content_type: contentType,
33
    owner_shared: totalShared,
34
    feed_share_external_url: shareExternalUrl,
35
    feed_save_reaction_url: saveReactionUrl,
36
    feed_delete_reaction_url: deleteReactionUrl,
37
    feed_increment_external_counter_url: incrementExternalCounterUrl,
38
    feed_my_reaction: feedMyReaction,
39
    feed_reactions: feedReactions,
40
    owner_external_shared: ownerExternalShared,
41
    feed_share_url: feedShareUrl,
42
    feed_unique: feedUnique
43
  } = useSelector(({ feed }) => feed.feeds.byId[id]);
44
  const labels = useSelector(({ intl }) => intl.labels);
45
  const dispatch = useDispatch();
46
 
47
  const [totalComments, setTotalComments] = useState(ownerComments);
48
  const [reaction, setReaction] = useState(feedMyReaction);
49
  const [ownerReactions, setOwnerReactions] = useState(feedReactions);
50
  const [externalShare, setExternalShare] = useState(ownerExternalShared);
51
  const [showComments, setShowComments] = useState(false);
52
 
53
  const setTotalShares = (value) => setExternalShare(value);
54
 
55
  const toggleComments = () => setShowComments((prev) => !prev);
56
 
57
  const updateReactions = ({ reactions }, currentReaction) => {
58
    setOwnerReactions(reactions);
59
    setReaction(currentReaction);
60
  };
61
 
62
  const shareFeed = () => {
63
    dispatch(openShareModal(feedShareUrl, shareModalTypes.SHARE, feedTypes.DASHBOARD, feedUnique));
64
  };
65
 
66
  const ExternalShareButton = withExternalShare(Button, shareExternalUrl);
67
  const ReactionButton = withReactions(Button);
68
 
69
  return (
70
    <>
71
      <Row>
72
        <Reactions reactions={ownerReactions} reactionsUrl={reactionsUrl} />
73
 
74
        <Row>
75
          {totalComments ? (
76
            <Typography variant='overline'>
77
              {`${totalComments} ${labels.comments?.toLowerCase()}`}
78
            </Typography>
79
          ) : null}
80
 
81
          {totalShared ? (
82
            <Typography variant='overline'>
83
              {`${totalShared} ${labels.shared?.toLowerCase()}`}
84
            </Typography>
85
          ) : null}
86
 
87
          {externalShare ? (
88
            <Typography variant='overline'>
89
              {`${externalShare} ${labels.sends?.toLowerCase()}`}
90
            </Typography>
91
          ) : null}
92
        </Row>
93
      </Row>
94
      <Widget.Actions styles={{ display: contentType === 'fast-survey' ? 'none' : 'flex' }}>
95
        <ReactionButton
96
          currentReactionType={reaction}
97
          saveUrl={saveReactionUrl}
98
          deleteUrl={deleteReactionUrl}
99
          onReaction={updateReactions}
100
        />
101
        <Button onClick={toggleComments}>
102
          <ChatOutlined />
103
          <Typography sx={{ display: { xs: 'none', md: 'inline-flex' } }} variant='overline'>
104
            {labels.comment}
105
          </Typography>
106
        </Button>
107
        <Button onClick={shareFeed}>
108
          <ShareOutlined />
109
          <Typography sx={{ display: { xs: 'none', md: 'inline-flex' } }} variant='overline'>
110
            {labels.share}
111
          </Typography>
112
        </Button>
113
        <ExternalShareButton shorterUrl={incrementExternalCounterUrl} setValue={setTotalShares}>
114
          <SendOutlined />
115
          <Typography sx={{ display: { xs: 'none', md: 'inline-flex' } }} variant='overline'>
116
            {labels.send}
117
          </Typography>
118
        </ExternalShareButton>
119
      </Widget.Actions>
120
      <Box
121
        sx={{
122
          display: showComments ? 'block' : 'none',
123
          padding: 0.5
124
        }}
125
      >
126
        <Comments
127
          comments={comments}
128
          addUrl={commentAddUrl}
129
          onAdd={({ totalComments }) => setTotalComments(totalComments)}
130
        />
131
      </Box>
132
    </>
133
  );
134
}