Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2970 | Rev 3694 | 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'
2970 stevensc 7
import { feedTypes } from '@store/feed/feed.types'
8
import { shareModalTypes } from '@store/share-modal/shareModal.types'
9
import { openShareModal } from '@store/share-modal/shareModal.actions'
2838 stevensc 10
 
11
import Widget from '@components/UI/Widget'
2846 stevensc 12
import Comments from '../linkedin/comments/comments'
2899 stevensc 13
import Reactions from '../reactions/reactions'
2970 stevensc 14
import withExternalShare from '../linkedin/withExternalShare'
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>
2899 stevensc 77
        <Reactions reactions={ownerReactions} reactionsUrl={reactionsUrl} />
2838 stevensc 78
 
79
        <Row>
2893 stevensc 80
          {totalComments ? (
2917 stevensc 81
            <Typography variant='overline'>
2893 stevensc 82
              {`${totalComments} ${labels.comments?.toLowerCase()}`}
83
            </Typography>
84
          ) : null}
2838 stevensc 85
 
2893 stevensc 86
          {totalShared ? (
2917 stevensc 87
            <Typography variant='overline'>
2893 stevensc 88
              {`${totalShared} ${labels.shared?.toLowerCase()}`}
89
            </Typography>
90
          ) : null}
2838 stevensc 91
 
2893 stevensc 92
          {externalShare ? (
2917 stevensc 93
            <Typography variant='overline'>
2893 stevensc 94
              {`${externalShare} ${labels.sends?.toLowerCase()}`}
95
            </Typography>
96
          ) : null}
2838 stevensc 97
        </Row>
98
      </Row>
99
      <Widget.Actions
100
        styles={{ display: contentType === 'fast-survey' ? 'none' : 'flex' }}
101
      >
102
        <ReactionButton
103
          currentReactionType={reaction}
104
          saveUrl={saveReactionUrl}
105
          deleteUrl={deleteReactionUrl}
106
          onReaction={updateReactions}
107
        />
108
        <Button onClick={toggleComments}>
109
          <ChatOutlined />
3274 stevensc 110
          <Typography
111
            sx={{ display: { xs: 'none', md: 'inline-flex' } }}
112
            variant='overline'
113
          >
114
            {labels.comment}
115
          </Typography>
2838 stevensc 116
        </Button>
117
        <Button onClick={shareFeed}>
118
          <ShareOutlined />
3274 stevensc 119
          <Typography
120
            sx={{ display: { xs: 'none', md: 'inline-flex' } }}
121
            variant='overline'
122
          >
123
            {labels.share}
124
          </Typography>
2838 stevensc 125
        </Button>
126
        <ExternalShareButton
127
          shorterUrl={incrementExternalCounterUrl}
128
          setValue={setTotalShares}
129
        >
130
          <SendOutlined />
3274 stevensc 131
          <Typography
132
            sx={{ display: { xs: 'none', md: 'inline-flex' } }}
133
            variant='overline'
134
          >
135
            {labels.send}
136
          </Typography>
2838 stevensc 137
        </ExternalShareButton>
138
      </Widget.Actions>
139
      <Box
140
        sx={{
2843 stevensc 141
          display: showComments ? 'block' : 'none',
142
          padding: 0.5
2838 stevensc 143
        }}
144
      >
2846 stevensc 145
        <Comments
146
          comments={comments}
147
          addUrl={commentAddUrl}
148
          onAdd={({ totalComments }) => setTotalComments(totalComments)}
149
        />
2838 stevensc 150
      </Box>
151
    </>
152
  )
153
}