Commit 1a2588b1 by JM Fantin

Merge branch 'acessoUsuario' into 'dev-sprint4'

Filtro de cards (adm ou votante) na tela de Inicio

See merge request !45
2 parents e04415e2 2023496b
import React, { Component } from 'react';
import { View, ScrollView, Dimensions } from 'react-native';
import { View, ScrollView, Dimensions, Text, FlatList, AsyncStorage } from 'react-native';
import { db } from '../config';
let salasRef = db.ref('salas/');
import BotaoNovaSala from '../components/BotaoNovaSala';
......@@ -8,42 +8,172 @@ import SemSalas from '../containers/SemSalas';
import CardSalaVotacao from '../components/CardSalaVotacao';
import Barra from '../components/Barra';
import getStatus from '../utils/getStatus';
import BotaoAlternativa from '../components/BotaoAlternativa';
import moment from 'moment';
import AuthService from '../shared/AuthService';
moment.defineLocale('pt-br', {
months: 'Janeiro_Fevereiro_Março_Abril_Maio_Junho_Julho_Agosto_Setembro_Outubro_Novembro_Dezembro'.split('_'),
monthsShort: 'Jan_Fev_Mar_Abr_Mai_Jun_Jul_Ago_Set_Out_Nov_Dez'.split('_'),
weekdays: 'Domingo_Segunda-feira_Terça-feira_Quarta-feira_Quinta-feira_Sexta-feira_Sábado'.split('_'),
weekdaysShort: 'Dom_Seg_Ter_Qua_Qui_Sex_Sáb'.split('_'),
weekdaysMin: 'Do_2ª_3ª_4ª_5ª_6ª_Sá'.split('_'),
weekdaysParseExact: true,
longDateFormat: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'DD/MM/YYYY',
LL: 'D [de] MMMM [de] YYYY',
LLL: 'D [de] MMMM [de] YYYY [às] HH:mm',
LLLL: 'dddd, D [de] MMMM [de] YYYY [às] HH:mm'
},
calendar: {
sameDay: '[Hoje às] LT',
nextDay: '[Amanhã às] LT',
nextWeek: 'dddd [às] LT',
lastDay: '[Ontem às] LT',
lastWeek: function () {
return (this.day() === 0 || this.day() === 6) ?
'[Último] dddd [às] LT' : // Saturday + Sunday
'[Última] dddd [às] LT'; // Monday - Friday
},
sameElse: 'L'
},
relativeTime: {
future: 'em %s',
past: 'há %s',
s: 'poucos segundos',
ss: '%d segundos',
m: 'um minuto',
mm: '%d minutos',
h: 'uma hora',
hh: '%d horas',
d: 'um dia',
dd: '%d dias',
M: 'um mês',
MM: '%d meses',
y: 'um ano',
yy: '%d anos'
},
dayOfMonthOrdinalParse: /\d{1,2}º/,
ordinal: '%dº'
});
export default class Inicio extends Component {
constructor(props) {
super(props);
this.state = {
salas: []
salas: [],
souAdm: false
}
}
static navigationOptions = {
title: 'Votações disponíveis',
};
componentWillMount() {
salasRef.orderByChild("uid").on('value', snapshot => {
let salas = snapshot.val();
if (salas != null) {
salas = Object.values(salas);
this.setState(() => ({
salas
}))
}
AsyncStorage.getItem('@UID').then(uid => {
if (salas != null) {
salas = Object.values(salas);
salas = salas.filter(sala => {
if(sala.adm_uid === uid){
return true;
}
if(sala.votantes){
return [...sala.votantes].filter(v => v.uid === uid).length;
}
});
this.setState(() => ({
salas, uid
}))
}
},
error => console.log('EEERROOOOU', error));
});
}
getStatus = (dataFinal, dataInicial, horaFinal, horaInicial, informacaoExtra) => {
// fazer cálculo para retornar se está em andamento, encerrada ou se vai iniciar;
this.testFunc();
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) {
return informacaoExtra ? `Disponível ${firstMoment.fromNow()}` : 'agendada';
}
if (finalMoment.diff(nowMoment) >= 0) {
return informacaoExtra ? `Encerra ${finalMoment.fromNow()}` : 'andamento';
}
//console.log('enc');
return informacaoExtra ? finalMoment.format('DD/MM/YYYY HH:mm') : 'encerrada';
}
handleVisualizar = (item) => {
if (item)
const { uid } = 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 });
else
} else {
this.props.navigation.navigate('Votacao', { 'sala': 'Não disponível' });
}
}
handleSelect = selected => {
this.setState({ selected });
}
testFunc = async () => {
// let res = await AsyncStorage.getItem('@UID');
}
getSalas = async () => {
}
getMinhasSalas = async salas => {
const uid = await AsyncStorage.get('@UID');
consol.log(uid)
return salas;
}
getDisponiveis = salas => {
return salas.map((item, index) => (
this.getStatus(item.dataFinal, item.dataInicial, item.horaFinal, item.horaInicial, false)
) != 'encerrada'
? <CardSalaVotacao
key={index}
onPress={() => this.handleVisualizar(item)}
status={this.getStatus(item.dataFinal,
item.dataInicial, item.horaFinal,
item.horaInicial)}
mensagem={this.getStatus(item.dataFinal,
item.dataInicial, item.horaFinal,
item.horaInicial, true)}
titulo={item.titulo}
/>
: null
)
}
render() {
const { salas } = this.state;
const { height } = Dimensions.get('screen');
// let x = await this.getMinhasSalas(salas);
return (
<View style={[styles.container, { height: height }]}>
<ScrollView style={{ maxHeight: height - 240, marginBottom: 5 }}>
......
import React, { Component } from 'react';
import { View, Image, TouchableOpacity,Text, StyleSheet, KeyboardAvoidingView } from 'react-native';
import { View, Image, TouchableOpacity,Text, StyleSheet, KeyboardAvoidingView, AsyncStorage } from 'react-native';
import { auth } from '../config';
import InputEmail from '../components/InputEmail';
import InputSenha from '../components/InputSenha';
import styles from '../styles/estilos';
import AuthService from '../shared/AuthService';
export default class Login extends Component {
constructor(props) {
......@@ -20,14 +21,28 @@ export default class Login extends Component {
const { email, senha } = this.state;
auth
.signInWithEmailAndPassword(email, senha)
.then((data) => this.props.navigation.navigate('Inicio'))
.catch(error => this.setState({ errorMessage: 'E-mail ou senha incorretos.' }));
.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')
)
//)
})
.catch(error => {
console.log(error);
this.setState({ errorMessage: 'E-mail ou senha incorretos.' })
})
}
static navigationOptions = {
title: 'Bem-vind@ ao eVote!'
};
static getUID = () => {
return AsyncStorage.getItem()
}
render(){
return(
<KeyboardAvoidingView style={styles.container} behavior="padding" enabled number="2">
......@@ -36,23 +51,21 @@ export default class Login extends Component {
</View>
<View style={{flex: 3}}>
<InputEmail
autoCorrect={false}
label=" "
keyboardType='email-address'
returnKeyType="next"
onChangeText={email => this.setState({ email })}
value={this.state.email}
placeholder='E-mail'
/>
autoCorrect={false}
keyboardType='email-address'
returnKeyType="next"
label={'login'}
onChangeText={email => this.setState({ email })}
value={this.state.email}
placeholder='E-mail' />
<InputSenha
label=" "
autoCorrect={false}
returnKeyType="go"
placeholder='Senha'
onChangeText={senha => this.setState({ senha })}
value={this.state.senha}
/>
<InputSenha
autoCorrect={false}
returnKeyType="go"
placeholder='Senha'
label={'senha'}
onChangeText={senha => this.setState({ senha })}
value={this.state.senha}/>
<Text style={custom.notice}>
{this.state.errorMessage}
......
import React, { Component } from 'react';
import { View, Text, ScrollView, KeyboardAvoidingView } from 'react-native';
import { View, Text, ScrollView, KeyboardAvoidingView, AsyncStorage } from 'react-native';
import Aviso from '../components/Aviso';
import BotaoAnterior from '../components/BotaoAnterior';
import BotaoProximo from '../components/BotaoProximo';
......@@ -38,7 +38,14 @@ export default class Sala extends Component {
headerLeft: null
};
horaInvalida = (hF, hI) => {
componentWillMount(){
AsyncStorage.getItem('@UID').then(uid => {
this.setState({sala: {...this.state.sala, adm_uid: uid}});
},
error => console.log('EEERROOOOU', error));
}
horaInvalida = (hF,hI) => {
const { dataFinal, dataInicial } = this.state.sala;
if (dataFinal == dataInicial) {
const horaFinal = hF.split(":");
......
import { AsyncStorage } from "react-native";
export class AuthService {
static setUID(uid) {
return AsyncStorage.setItem('@UID', uid);
}
static getUID() {
return AsyncStorage.getItem('@UID');
}
}
// export { AuthService }
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!