Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5737 stevensc 1
import React, { useEffect, useRef, useState } from 'react'
5577 stevensc 2
import RecommendIcon from '@mui/icons-material/Recommend'
3
import FavoriteIcon from '@mui/icons-material/Favorite'
4
import VolunteerActivismIcon from '@mui/icons-material/VolunteerActivism'
5734 stevensc 5
import { debounce } from '../../../utils'
5737 stevensc 6
import useOutsideClick from '../../../hooks/useOutsideClick'
5574 stevensc 7
 
5667 stevensc 8
export const ReactionButton = () => {
5668 stevensc 9
  const [settedReaction, setSettedReaction] = useState('r')
5734 stevensc 10
  const [showReactions, setShowReactions] = useState(false)
5737 stevensc 11
  const rectionBtn = useRef(null)
12
  const outsideClick = useOutsideClick(rectionBtn)
5667 stevensc 13
 
14
  const reactions = [
15
    {
16
      type: 'r',
5739 stevensc 17
      icon: <RecommendIcon style={{ color: '#7405f9' }} />,
5667 stevensc 18
    },
19
    {
20
      type: 'f',
5739 stevensc 21
      icon: <FavoriteIcon style={{ color: '#E7A33E' }} />,
5667 stevensc 22
    },
23
    {
24
      type: 'v',
5739 stevensc 25
      icon: <VolunteerActivismIcon style={{ color: '#7FC15E' }} />,
5667 stevensc 26
    },
27
  ]
28
 
5741 stevensc 29
  const onHover = debounce(() => setShowReactions(true), 500)
5734 stevensc 30
 
5743 stevensc 31
  const onUnhover = debounce((e) => setShowReactions(false), 500)
5741 stevensc 32
 
5739 stevensc 33
  const handleClick = (reaction) => {
34
    setSettedReaction(reaction)
35
    setShowReactions(false)
36
  }
37
 
5737 stevensc 38
  useEffect(() => {
39
    if (outsideClick) {
40
      setShowReactions(false)
41
    }
42
  }, [outsideClick])
43
 
5577 stevensc 44
  return (
5738 stevensc 45
    <button
46
      type="button"
47
      className="reaction-btn"
5743 stevensc 48
      onMouseOver={onHover}
49
      onMouseOut={onUnhover}
5738 stevensc 50
      ref={rectionBtn}
51
    >
5737 stevensc 52
      {reactions.map((reaction) =>
53
        reaction.type === settedReaction ? reaction.icon : null
54
      )}
5734 stevensc 55
      <div className={`reactions ${showReactions ? 'active' : ''}`}>
5669 stevensc 56
        {reactions.map((reaction) => (
57
          <button
58
            key={reaction.type}
5739 stevensc 59
            onClick={() => handleClick(reaction.type)}
5669 stevensc 60
          >
61
            {reaction.icon}
62
          </button>
63
        ))}
5577 stevensc 64
      </div>
65
    </button>
66
  )
67
}