Skip to content
Snippets Groups Projects
StarsContainer.tsx 1.15 KiB
Newer Older
  • Learn to ignore specific revisions
  • import React, { useEffect, useState } from 'react'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import StyledIcon from 'components/CommonKit/Icon/StyledIcon'
    
    import starIcon from 'assets/icons/visu/challenge/star.svg'
    import starFilled from 'assets/icons/visu/challenge/starFilled.svg'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    interface StarsContainerProps {
    
      result: number
    
      isQuizBegin?: boolean
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    }
    
    const StarsContainer: React.FC<StarsContainerProps> = ({
    
      result,
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    }: StarsContainerProps) => {
    
      const [elements] = useState<string[]>([])
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    
    
      useEffect(() => {
        const renderStars = () => {
    
          //To be removed when action and explorations will be done
    
          if (result === 5) {
            elements.splice(0, elements.length)
          }
    
          for (let i = 0; i < 5; i++) {
    
            if (i < result) elements.push(starFilled)
    
            else if (i >= result) elements.push(starIcon)
          }
        }
        renderStars()
      }, [result, elements])
    
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      return (
        <div className="stars">
    
          {elements.map((star, i) => {
    
            return (
              <StyledIcon
                key={i}
                className="star"
                icon={star}
                size={isQuizBegin ? 25 : 15}
              />
            )
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        </div>
      )
    }
    
    export default StarsContainer