Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16745 Rev 16750
Línea 69... Línea 69...
69
  time,
69
  time,
70
  resultType
70
  resultType
71
}) => {
71
}) => {
72
  const [remainingTime, setRemainingTime] = useState('00:00:00')
72
  const [remainingTime, setRemainingTime] = useState('00:00:00')
73
  const [isActive, setIsActive] = useState(Boolean(active))
73
  const [isActive, setIsActive] = useState(Boolean(active))
-
 
74
  const [totalVotes, setTotalVotes] = useState(0)
74
  const timeRef = useRef(time)
75
  const timeRef = useRef(time)
75
  const voteRef = useRef(0)
-
 
Línea 76... Línea 76...
76
 
76
 
77
  function getTimeDiff(segundos) {
77
  function getTimeDiff(segundos) {
78
    // Obtener la fecha y hora actual
78
    // Obtener la fecha y hora actual
Línea 128... Línea 128...
128
    }
128
    }
129
  }, [])
129
  }, [])
Línea 130... Línea 130...
130
 
130
 
131
  useEffect(() => {
131
  useEffect(() => {
132
    if (!votes) return
132
    if (!votes) return
-
 
133
    const total = votes.reduce((total, vote) => total + vote, 0)
133
    votes.forEach((vote) => (voteRef.current += Number(vote)))
134
    setTotalVotes(total)
Línea 134... Línea 135...
134
  }, [])
135
  }, [])
135
 
136
 
136
  return (
137
  return (
137
    <form className={styles.survey_form}>
138
    <form className={styles.survey_form}>
138
      <h3>{question}</h3>
-
 
139
      {resultType === 'pu' && (
139
      <h3>{question}</h3>
140
        <span
-
 
141
          title="Los resultados estaran disponibles al finalizar la
-
 
142
          encuesta."
140
      {resultType === 'pu' && (
143
        >
141
        <span title="El número de votos es visible para todos los usuarios">
144
          <PublicIcon /> Público
142
          <PublicIcon /> Público
145
        </span>
143
        </span>
146
      )}
144
      )}
147
      {resultType === 'pr' && (
145
      {resultType === 'pr' && (
148
        <span title="Los resultados de la votación son privados.">
146
        <span title="Los resultados de la votación son privados">
149
          <PrivateIcon /> Privado
147
          <PrivateIcon /> Privado
150
        </span>
148
        </span>
151
      )}
149
      )}
152
      {answers.map(
150
      {answers.map(
153
        (option, index) =>
151
        (option, index) =>
154
          option && (
152
          option && (
155
            <RadioButton
-
 
156
              disabled={!isActive}
153
            <RadioButton
157
              porcentage={
-
 
158
                !time && votes && getPorcentage(votes[index], voteRef.current)
154
              disabled={!isActive}
159
              }
155
              porcentage={votes && getPorcentage(votes[index], totalVotes)}
160
              key={index}
156
              key={index}
161
            >
157
            >
162
              <input
158
              <input
163
                type="radio"
159
                type="radio"
164
                name="vote"
160
                name="vote"
165
                id={`vote-${index + 1}`}
161
                id={`vote-${index + 1}`}
166
                value={index + 1}
162
                value={index + 1}
167
                disabled
163
                disabled
168
              />
164
              />
169
              <label htmlFor={`vote-${index + 1}`}>{option}</label>
165
              <label htmlFor={`vote-${index + 1}`}>{option}</label>
170
              {!time && votes && (
166
              {votes && (
171
                <span className="mb-0">
167
                <span className="mb-0">
172
                  {getPorcentage(votes[index], voteRef.current)}%
168
                  {getPorcentage(votes[index], totalVotes)}%
173
                </span>
169
                </span>
174
              )}
170
              )}
175
            </RadioButton>
171
            </RadioButton>