confereVoto iniciado

1 parent 78a0763c
Showing with 31 additions and 4 deletions
import React, { Component } from 'react';
import { Text, View, FlatList, ScrollView } from 'react-native';
import { Text, View, FlatList, ScrollView, AsyncStorage } from 'react-native';
import QuestaoCard from '../components/QuestaoCard';
import styles from '../styles/estilos';
import andamento from '../styles/andamento';
......@@ -17,8 +17,6 @@ export default class Andamento extends Component {
static navigationOptions = ({ navigation }) => ({
title: `Sala: ${navigation.state.params.titulo || 'Não localizado'}`
});
handleSubmit=()=>{}
componentWillMount() {
const questoes = this.props.navigation.getParam('questoes', null);
......@@ -30,6 +28,15 @@ export default class Andamento extends Component {
this.setState({votantes, qtdVotantes: votantes.length});
}
componentDidMount(){
const uid = this.getUID();
this.setState({uid});
}
getUID = async () => {
return await AsyncStorage.getItem('@UID');
}
getQtdVotos = (index) => {
const { questoes } = this.state;
let cont = 0;
......@@ -39,6 +46,25 @@ export default class Andamento extends Component {
return cont;
}
confereVoto = (alternativa) => {
const { uid } = this.state;
let result = 0;
if(alternativa[2]) {
const votantes = alternativa[2];
if(votantes.length > 1)
result = votantes.filter(id => id === uid).length;
else if(votantes.length == 1){
if(votantes == uid) {
result = 1;
}
}
}
if(result > 0)
return true;
else
return false;
}
renderItem = ({ item, index }) => {
const { qtdVotantes } = this.state;
const alfabeto = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'];
......@@ -48,9 +74,10 @@ export default class Andamento extends Component {
<QuestaoCard key={item.pergunta} text={`Q${index+1}. ${item.pergunta}`}/>
{
item.alternativas.map((alternativa, index) => {
let voto = this.confereVoto(alternativa);
return (
<View key={index + 1 } style={andamento.alternativas}>
<IndiceAlternativa indice={`${alfabeto[index]})`} />
<IndiceAlternativa destaque={voto} indice={`${alfabeto[index]})`} />
<BarraProgresso progresso={Number(((alternativa[1]/totalDeVotos)*100).toFixed(1)) || 0} />
<Text>{Number(((alternativa[1]/totalDeVotos)*100).toFixed(5)) || 0}%</Text>
</View>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!