Proyectos de Subversion LeadersLinked - SPA

Rev

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

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