-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (22 loc) · 816 Bytes
/
script.js
File metadata and controls
26 lines (22 loc) · 816 Bytes
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
const result = document.getElementById('result')
const input = document.getElementById('input')
const button = document.getElementById('button')
const db = firebase.firestore();
button.addEventListener('click', async () => {
const sentence = input.value
const id = Date.now().toString()
const res = await fetch(`http://58bb46a41a1d.ngrok.io/api/analyze_sentiment/${id}?sentence=${sentence}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
// const data = await res.json()
// result.textContent = `Sentiment: ${data.sentiment}`
db.collection("sentiment-data").doc(id)
.onSnapshot(function (doc) {
console.log(doc.data())
result.textContent = `Sentiment (from firestore): ${doc.data().sentiment}`
});
})