-
Notifications
You must be signed in to change notification settings - Fork 1
/
fire_opnion.js
51 lines (43 loc) · 1.58 KB
/
fire_opnion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Import the functions you need from the SDKs you need
//import { initializeApp } from "firebase/app";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
const firebase = require("firebase");
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAJnSYJ1wqYotEcBB9z5UI7o4fMP00Dl1s",
authDomain: "pokemonleopoldo-4c89a.firebaseapp.com",
databaseURL: "https://pokemonleopoldo-4c89a-default-rtdb.firebaseio.com",
projectId: "pokemonleopoldo-4c89a",
storageBucket: "pokemonleopoldo-4c89a.appspot.com",
messagingSenderId: "626398900153",
appId: "1:626398900153:web:57d06fd74445011d6b9068"
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
// Adicione um documento vazio na coleção 'user_opinion'
db.collection("user_opinion").add({
text: ""
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
// Escute o evento de envio do formulário
document.getElementById('yourOpinion').addEventListener('submit', function(evt) {
evt.preventDefault();
// Obtenha o valor da opinião
var opinion = document.getElementById('opnion').value;
// Adicione a opinião ao Firestore
db.collection("user_opinion").add({
opinion: opinion,
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
});