Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6486 | Rev 6488 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 6486 Rev 6487
Línea 86... Línea 86...
86
  addNotification, // Redux action
86
  addNotification, // Redux action
87
  updateFeed, // Redux action
87
  updateFeed, // Redux action
88
}) => {
88
}) => {
89
  const [remainingTime, setRemainingTime] = useState('00:00:00')
89
  const [remainingTime, setRemainingTime] = useState('00:00:00')
90
  const [isActive, setIsActive] = useState(Boolean(active))
90
  const [isActive, setIsActive] = useState(Boolean(active))
-
 
91
  const [totalVotes, setTotalVotes] = useState(0)
91
  const timeRef = useRef(time)
92
  const timeRef = useRef(time)
92
  const voteRef = useRef(0)
-
 
93
  const { register, handleSubmit } = useForm()
93
  const { register, handleSubmit } = useForm()
Línea 94... Línea 94...
94
 
94
 
95
  const sendVote = handleSubmit(({ vote }) => {
95
  const sendVote = handleSubmit(({ vote }) => {
96
    setIsActive(false)
96
    setIsActive(false)
Línea 171... Línea 171...
171
    }
171
    }
172
  }, [])
172
  }, [])
Línea 173... Línea 173...
173
 
173
 
174
  useEffect(() => {
174
  useEffect(() => {
175
    if (!votes) return
175
    if (!votes) return
-
 
176
    const total = votes.reduce((acum, current) => acum + Number(current), 0)
176
    votes.forEach((vote) => (voteRef.current += Number(vote)))
177
    setTotalVotes(total)
Línea 177... Línea 178...
177
  }, [votes])
178
  }, [votes])
178
 
179
 
179
  return (
180
  return (
Línea 195... Línea 196...
195
      {answers.map(
196
      {answers.map(
196
        (option, index) =>
197
        (option, index) =>
197
          option && (
198
          option && (
198
            <RadioButton
199
            <RadioButton
199
              disabled={!isActive}
200
              disabled={!isActive}
200
              porcentage={
-
 
201
                voteRef.current && getPorcentage(votes[index], voteRef.current)
201
              porcentage={totalVotes && getPorcentage(votes[index], totalVotes)}
202
              }
-
 
203
              key={index}
202
              key={index}
204
            >
203
            >
205
              <input
204
              <input
206
                type="radio"
205
                type="radio"
207
                name="vote"
206
                name="vote"
Línea 209... Línea 208...
209
                disabled={!isActive}
208
                disabled={!isActive}
210
                ref={register({ required: true })}
209
                ref={register({ required: true })}
211
                value={index + 1}
210
                value={index + 1}
212
              />
211
              />
213
              <label htmlFor={`vote-${index + 1}`}>{option}</label>
212
              <label htmlFor={`vote-${index + 1}`}>{option}</label>
214
              {voteRef.current && (
213
              {totalVotes && (
215
                <span className="mb-0">
214
                <span className="mb-0">
216
                  {getPorcentage(votes[index], voteRef.current)}%
215
                  {getPorcentage(votes[index], totalVotes)}%
217
                </span>
216
                </span>
218
              )}
217
              )}
219
            </RadioButton>
218
            </RadioButton>
220
          )
219
          )
221
      )}
220
      )}