Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5738 | Rev 5741 | 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
 
5734 stevensc 29
  const onHover = debounce(() => setShowReactions(true), 1000)
30
 
5739 stevensc 31
  const handleClick = (reaction) => {
32
    setSettedReaction(reaction)
33
    setShowReactions(false)
34
  }
35
 
5737 stevensc 36
  useEffect(() => {
37
    if (outsideClick) {
38
      setShowReactions(false)
39
    }
40
  }, [outsideClick])
41
 
5577 stevensc 42
  return (
5738 stevensc 43
    <button
44
      type="button"
45
      className="reaction-btn"
46
      onMouseEnter={onHover}
47
      ref={rectionBtn}
48
    >
5737 stevensc 49
      {reactions.map((reaction) =>
50
        reaction.type === settedReaction ? reaction.icon : null
51
      )}
5734 stevensc 52
      <div className={`reactions ${showReactions ? 'active' : ''}`}>
5669 stevensc 53
        {reactions.map((reaction) => (
54
          <button
55
            key={reaction.type}
5739 stevensc 56
            onClick={() => handleClick(reaction.type)}
5669 stevensc 57
          >
58
            {reaction.icon}
59
          </button>
60
        ))}
5577 stevensc 61
      </div>
62
    </button>
63
  )
64
}