Skip to content

Instantly share code, notes, and snippets.

@FDSoftware
Created December 1, 2019 22:46
Show Gist options
  • Save FDSoftware/e396bd567ffc54faf5bac79b2c12c976 to your computer and use it in GitHub Desktop.
Save FDSoftware/e396bd567ffc54faf5bac79b2c12c976 to your computer and use it in GitHub Desktop.
<template>
<div class="Questions">
<v-card class="mx-auto mt-1 ml-5" max-width="400" outlined>
<v-card-subtitle>Preguntas de la comunidad :D</v-card-subtitle>
<v-divider></v-divider>
<v-list-item three-line>
<v-avatar size="64">
<img alt="Avatar" :src="preguntaActual.Foto" />
</v-avatar>
<v-list-item-content class="pl-4">
<div class="overline mb-4">el {{ preguntaActual.Fecha }}</div>
<v-list-item-title class="headline mb-1">
{{ preguntaActual.Usuario }}:
</v-list-item-title
>
<v-list-item-subtitle> {{ preguntaActual.QA }} </v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-card-actions>
<v-btn color="primary" class="mx-auto" v-on:click="nextQA()">Siguiente pregunta</v-btn>
</v-card-actions>
</v-card>
</div>
</template>
<script>
import { db } from "../firecfg";
export default {
data: () => ({
preguntas2: [],
preguntaActual: {
ID: 1,
Fecha: "null",
Foto:"https://thumbs.gfycat.com/RealisticRightEuropeanfiresalamander-small.gif",
Usuario: "DJ Pepe",
QA: "toca el boton magico para tener la primer pregunta",
Estado: 1
},
QA_Index: 0,
iniciado: false
//
}),
mounted() {
this.init();
},
methods: {
init() {
let preguntasRef = db.ref("questions");
preguntasRef
.orderByChild("Estado")
.equalTo(1)
.once("value", snapshot => {
this.up(snapshot.val().filter(Boolean));
// eslint-disable-next-line no-console
if (!this.iniciado) {
this.iniciado = true;
this.nextQA();
}
});
},
up(data2) {
this.preguntas2 = data2;
},
nextQA() {
this.preguntaActual = this.preguntas2[this.QA_Index];
let updateData = db.ref("questions/" + this.preguntaActual.ID).set(
{
ID: this.preguntaActual.ID ,
Fecha: this.preguntaActual.Fecha,
Foto: this.preguntaActual.Foto,
Usuario: this.preguntaActual.Usuario,
QA: this.preguntaActual.QA,
Estado: 3
},
function(error) {
if(error){
// eslint-disable-next-line no-console
console.error("Nos mandamo cagada al escribir ameo': ");
// eslint-disable-next-line no-console
console.error(error);
}
}
);
// eslint-disable-next-line no-console
console.log(updateData);
this.QA_Index++;
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment