aviso de que já votou na sala

1 parent e24fa411
{
"devToolsPort": 19002,
"expoServerPort": 19000,
"expoServerNgrokUrl": "https://xz-g8k.evote.rn-evote.exp.direct",
"packagerNgrokUrl": "https://packager.xz-g8k.evote.rn-evote.exp.direct",
"ngrokPid": 7194,
"packagerPort": 19001,
"packagerPid": 7094,
"devToolsPort": 19002
"packagerPid": 9125,
"expoServerNgrokUrl": "https://cb-8vg.evote.rn-evote.exp.direct",
"packagerNgrokUrl": "https://packager.cb-8vg.evote.rn-evote.exp.direct",
"ngrokPid": 9179
}
\ No newline at end of file
......@@ -3,5 +3,5 @@
"lanType": "ip",
"dev": true,
"minify": false,
"urlRandomness": "xz-g8k"
"urlRandomness": "cb-8vg"
}
\ No newline at end of file
......@@ -8,11 +8,12 @@ class BotaoGrande extends Component {
}
render() {
const { backgroundColor, texto, onPress} = this.props;
const { backgroundColor, texto, onPress, disabled } = this.props;
return (
<TouchableOpacity
style={[styles.buttonStyle, {backgroundColor: backgroundColor}]}
onPress={onPress}
onPress={onPress}
disabled={disabled}
>
<Text style={styles.textStyle}>
{texto}
......@@ -25,11 +26,13 @@ class BotaoGrande extends Component {
BotaoGrande.propTypes = {
backgroundColor: PropTypes.oneOf(['#7500CF', '#00E576']),
texto: PropTypes.string.isRequired,
onPress: PropTypes.func.isRequired
onPress: PropTypes.func.isRequired,
disabled: PropTypes.bool
};
BotaoGrande.defaultProps = {
backgroundColor: '#7500CF',
disabled: false
};
const styles = StyleSheet.create({
......
......@@ -57,7 +57,7 @@ export default class Andamento extends Component {
): "Votação ainda não encerrou."
}/>
</View>
<BotaoGrande texto="Andamento" onPress={() => this.andamentoVotos()}/>
<BotaoGrande texto="Andamento" disabled={!encerrou} onPress={() => this.andamentoVotos()}/>
</View>
);
}
......
......@@ -36,7 +36,6 @@ export default class Andamento extends Component {
questoes[index].alternativas.map(alternativa => {
cont = cont + alternativa[1];
});
console.log("TOTAL VOTOS: "+ cont);
return cont;
}
......
......@@ -4,16 +4,25 @@ import styles from '../styles/estilos';
import SemSalas from '../containers/SemSalas';
import CardSalaVotacao from '../components/CardSalaVotacao';
import Barra from '../components/Barra';
import moment from 'moment';
import moment from 'moment';
import getStatus from '../utils/getStatus';
class Historico extends Component {
constructor(props) {
super(props)
this.state = {
salas: []
}
}
static navigationOptions = {
title: 'Histórico de Votações',
};
componentWillMount(){
const salas = this.props.navigation.getParam('salas', []);
this.setState({salas});
}
handleVisualizar = (item) => {
if (item)
this.props.navigation.navigate('Andamento', { 'sala': item, 'encerrou': true });
......@@ -21,18 +30,8 @@ class Historico extends Component {
this.props.navigation.navigate('Andamento', { 'sala': 'Não disponível' });
}
getStatus = (dataFinal, dataInicial, horaFinal, horaInicial, informacaoExtra) => {
let firstMoment = moment(`${dataInicial} ${horaInicial}`, 'DD/MM/YYYY HH:mm');
let finalMoment = moment(`${dataFinal} ${horaFinal}`, 'DD/MM/YYYY HH:mm');
let nowMoment = moment();
if(!(firstMoment.diff(nowMoment)>0) && !(finalMoment.diff(nowMoment)>=0)) {
return informacaoExtra? finalMoment.format('DD/MM/YYYY HH:mm') : 'encerrada';
}
}
render() {
const salas = this.props.navigation.getParam('salas', []);
const { salas } = this.state;
const { height } = Dimensions.get('screen');
return (
<View style={[styles.container, { height: height }]}>
......@@ -41,16 +40,16 @@ class Historico extends Component {
{
salas.length > 0 ?
salas.map((item, index) =>
(this.getStatus(item.dataFinal,
(getStatus(item.dataFinal,
item.dataInicial, item.horaFinal,
item.horaInicial, false)) == 'encerrada'?
<CardSalaVotacao
key={index}
onPress={() => this.handleVisualizar(item)}
status={this.getStatus(item.dataFinal,
status={getStatus(item.dataFinal,
item.dataInicial, item.horaFinal,
item.horaInicial)}
mensagem={this.getStatus(item.dataFinal,
mensagem={getStatus(item.dataFinal,
item.dataInicial, item.horaFinal,
item.horaInicial, true)}
titulo={item.titulo}
......
import React, { Component } from 'react';
import { View, ScrollView, Dimensions, AsyncStorage } from 'react-native';
import { View, ScrollView, Dimensions, AsyncStorage, Alert } from 'react-native';
import { db } from '../config';
let salasRef = db.ref('salas/');
import BotaoNovaSala from '../components/BotaoNovaSala';
......@@ -45,13 +45,42 @@ export default class Inicio extends Component {
});
}
podeVotar = (item, indice) => {
const { uid } = this.state;
const { questoes } = item;
let result = true;
//se já votou retorna false
questoes.map((questao, index) => {
let { alternativas } = questao;
alternativas.forEach(element => {
if(element && element[2]) {
result = !(element[2].filter(id => id === uid).length);
return result;
}
});
});
if(result)
return true;
else
return false;
}
handleVisualizar = (item, index) => {
const { uid, salas } = this.state
if (item){
if(uid && item.adm_uid === uid){
return this.props.navigation.navigate('Andamento', { 'sala': item });
}
this.props.navigation.navigate('Votacao', { 'sala': item, 'salas': salas, 'indiceSala': index });
if(this.podeVotar(item, index))
this.props.navigation.navigate('Votacao', { 'sala': item, 'salas': salas, 'indiceSala': index });
else
return Alert.alert(
'⚠️ Aviso:',
'Você já votou nesta sala!',
[
{text: 'OK'},
]
);
} else {
this.props.navigation.navigate('Votacao', { 'sala': item, 'salas': salas, 'indiceSala': index });
}
......@@ -63,15 +92,12 @@ export default class Inicio extends Component {
getHistorico = salas => salas.filter(item => {
const {dataFinal, dataInicial, horaFinal, horaInicial } = item;
return this.getStatus(dataFinal, dataInicial, horaFinal, horaInicial, false) == 'encerrada';
return getStatus(dataFinal, dataInicial, horaFinal, horaInicial, false) == 'encerrada';
})
render() {
const { salas } = this.state;
const { height } = Dimensions.get('screen');
const salasmock = [{
dataFinal: '28/06/2019', dataInicial:'28/06/2019', horaFinal:'28/06/2019', horaInicial:'28/06/2019', descricao:'a',titulo:'a'
}]
return (
<View style={[styles.container, { height: height }]}>
<ScrollView style={{ maxHeight: height - 240, marginBottom: 5 }}>
......
......@@ -22,7 +22,6 @@ export default class Login extends Component {
auth
.signInWithEmailAndPassword(email, senha)
.then((data) => {
console.log(JSON.stringify(data));
// AuthService.setUID(data.user.uid).then(
AsyncStorage.setItem('@UID', data.user.uid).then(
() => this.props.navigation.navigate('Inicio')
......
......@@ -42,7 +42,7 @@ export default class Sala extends Component {
AsyncStorage.getItem('@UID').then(uid => {
this.setState({sala: {...this.state.sala, adm_uid: uid}});
},
error => console.log('EEERROOOOU', error));
error => console.log('Verifique as credencias.', error));
}
horaInvalida = (hF,hI) => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!