Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3020 Rev 3021
Línea 2... Línea 2...
2
import { useForm } from 'react-hook-form'
2
import { useForm } from 'react-hook-form'
3
import { styled, Typography } from '@mui/material'
3
import { styled, Typography } from '@mui/material'
4
import { Public, LockClock } from '@mui/icons-material'
4
import { Public, LockClock } from '@mui/icons-material'
Línea 5... Línea 5...
5
 
5
 
-
 
6
import { axios } from '@utils'
6
import { axios } from '@utils'
7
import { getTimeDiff } from '@utils/dates'
7
import { updateFeed } from '@store/feed/feed.actions'
8
import { updateFeed } from '@store/feed/feed.actions'
Línea 8... Línea 9...
8
import { addNotification } from '@store/notification/notification.actions'
9
import { addNotification } from '@store/notification/notification.actions'
9
 
10
 
Línea 43... Línea 44...
43
        if (!cur) return acc
44
        if (!cur) return acc
44
        return acc + cur
45
        return acc + cur
45
      }, 0),
46
      }, 0),
46
    [votes]
47
    [votes]
47
  )
48
  )
-
 
49
  const timeRemaining = useMemo(() => getTimeDiff(time), [time])
Línea 48... Línea 50...
48
 
50
 
Línea 49... Línea 51...
49
  const { control, handleSubmit } = useForm()
51
  const { control, handleSubmit } = useForm()
50
 
52
 
Línea 71... Línea 73...
71
      .catch((err) => {
73
      .catch((err) => {
72
        addNotification({ style: 'danger', msg: err.message })
74
        addNotification({ style: 'danger', msg: err.message })
73
      })
75
      })
74
  })
76
  })
Línea 75... Línea -...
75
 
-
 
76
  function getTimeDiff(segundos) {
-
 
77
    const currentDate = new Date()
-
 
78
    const futureDate = new Date(currentDate.getTime() + segundos * 1000)
-
 
79
    const diff = futureDate - currentDate
-
 
80
 
-
 
81
    const days = Math.floor(diff / (1000 * 60 * 60 * 24))
-
 
82
    const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
-
 
83
    const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
-
 
84
 
-
 
85
    return `${addZero(days)}d ${addZero(hours)}h ${addZero(minutes)}m`
-
 
86
  }
-
 
87
 
-
 
88
  function addZero(unit) {
-
 
89
    return String(unit).padStart(2, '0')
-
 
90
  }
-
 
91
 
77
 
92
  function getPorcentage(n, total) {
78
  function getPorcentage(n, total) {
93
    return (n / total) * 100
79
    return (n / total) * 100
Línea 94... Línea 80...
94
  }
80
  }
Línea 102... Línea 88...
102
          <Typography
88
          <Typography
103
            variant='overline'
89
            variant='overline'
104
            title='El número de votos es visible para todos los usuarios'
90
            title='El número de votos es visible para todos los usuarios'
105
            sx={{ paddingBottom: (theme) => theme.spacing(0.5) }}
91
            sx={{ paddingBottom: (theme) => theme.spacing(0.5) }}
106
          >
92
          >
107
            <Public /> Público
93
            <Public sx={{ fontSize: '1.3rem' }} /> Público
108
          </Typography>
94
          </Typography>
109
        ) : (
95
        ) : (
110
          <Typography
96
          <Typography
111
            variant='overline'
97
            variant='overline'
112
            title='Los resultados de la votación son privados'
98
            title='Los resultados de la votación son privados'
113
            sx={{ paddingBottom: (theme) => theme.spacing(0.5) }}
99
            sx={{ paddingBottom: (theme) => theme.spacing(0.5) }}
114
          >
100
          >
115
            <LockClock /> Privado
101
            <LockClock sx={{ fontSize: '1.3rem' }} /> Privado
116
          </Typography>
102
          </Typography>
117
        )}
103
        )}
Línea 118... Línea 104...
118
 
104
 
119
        <form onChange={sendVote}>
105
        <form onChange={sendVote}>
Línea 141... Línea 127...
141
                <CheckboxInput
127
                <CheckboxInput
142
                  name='vote'
128
                  name='vote'
143
                  value={index + 1}
129
                  value={index + 1}
144
                  label={answer}
130
                  label={answer}
145
                  control={control}
131
                  control={control}
146
                  styles={{
132
                  labelStyles={{
147
                    display: 'flex',
133
                    display: 'flex',
148
                    alignItems: 'center',
134
                    alignItems: 'center',
149
                    gap: 0.5
135
                    gap: 0.5,
-
 
136
                    margin: 0
150
                  }}
137
                  }}
-
 
138
                  checkBoxStyles={{ padding: 0 }}
151
                />
139
                />
Línea 152... Línea 140...
152
 
140
 
153
                {totalVotes ? (
141
                {totalVotes ? (
154
                  <Typography variant='overline'>
142
                  <Typography variant='overline'>
Línea 157... Línea 145...
157
                ) : null}
145
                ) : null}
158
              </AnswerContainer>
146
              </AnswerContainer>
159
            )
147
            )
160
          })}
148
          })}
Línea 161... Línea 149...
161
 
149
 
-
 
150
          <Typography variant='overline'>
-
 
151
            Tiempo restante: {timeRemaining}
Línea 162... Línea 152...
162
          <Typography variant='overline'>Tiempo restante: </Typography>
152
          </Typography>
163
 
153
 
164
          {!active && (
154
          {!active && (
165
            <Typography variant='overline'>
155
            <Typography variant='overline'>