-
Notifications
You must be signed in to change notification settings - Fork 0
/
sportsdb.js
61 lines (50 loc) · 2.08 KB
/
sportsdb.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
52
53
54
55
56
57
58
59
60
61
// Authors: Jacob Wilson, Kevin Nguyen
//declare text and Button
const textBox = document.getElementById("textbox");
var button = document.getElementById('myBtn');// Read Data
//will get complete collection with this method;
// Selectors
const elementsArray = [];
elementsArray.push(document.getElementById("textBox"));
//tr rows
//td columns
const ref = db.collection("sports").orderBy("datetime");
ref.onSnapshot(function (snapshot) {
snapshot.docChanges().forEach(function (change) {
if (change.type === "added") {
const data = change.doc.data();
//find latest updates
const nodeTr = document.createElement("tr");
const nodeauthor = document.createElement("td");
const nodemsg = document.createElement("td");
const nodetime = document.createElement("td");
//add to html --> KEEP IN ORDER WHEN USED ANYWHERE IN CRUD
nodeauthor.innerHTML += data.author;
nodemsg.innerHTML += data.Message;
nodetime.innerHTML += data.datetime;
//add new nodes q
nodeTr.appendChild(nodeauthor);
nodeTr.appendChild(nodemsg);
nodeTr.appendChild(nodetime);
//Update Page
nodeTr.id = `${change.doc.id}`;
table.appendChild(nodeTr);
//allows to shift when mouse is over
document.getElementById(nodeTr.id).onmouseover = function(){
this.style.backgroundColor = "rgba(0, 217, 255, 0.979)";
this.style.transform = "translate(33px,0)";
}
document.getElementById(nodeTr.id).onmouseout = function(){
this.style.backgroundColor = "white";
this.style.transform = "translate(0px,0)";
}
}else if (change.type === "modified") {
console.log("Modified ", change.doc.data());
} else if (change.type === "removed") {
const elem = document.getElementById(change.doc.id);
table.removeChild(elem);
}
});
});
// Email will be handled below. Sends notification of success of schedule and message being sent.
// Actual sending of Messages are handled by the other Mercury messanger.