-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_classroom.js
54 lines (52 loc) · 1.78 KB
/
student_classroom.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
auth.onAuthStateChanged((user) => {
if (user == null) window.location.replace("student-login.html");
});
window.addEventListener("DOMContentLoaded", () => {
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get("id");
console.log(myParam);
db.collection("messages")
.doc(myParam)
.onSnapshot((snapshot) => {
const data = snapshot.data();
document.getElementById("message-container").innerHTML = "";
for (key in data) {
const div = document.createElement("div");
div.className = "callout callout-primary";
div.style = "border-radius:20px;";
div.innerHTML = `<h4>Faculty - ${data[key].timestamp}</h4>${data[key].message}`;
console.log(div);
document.getElementById("message-container").appendChild(div);
}
});
db.collection("documents")
.doc(myParam)
.onSnapshot((snapshot) => {
const data = snapshot.data();
console.log("documents", data);
document.getElementById("documents-container").innerHTML = "";
for (key in data) {
const div = document.createElement("div");
div.className = "callout callout-danger";
div.style = "border-radius: 20px;";
div.innerHTML = `<h5>${data[key].title}</h5>
<p>${data[key].description}</p>
<a href="${data[key].link}" download
>Click here to download</a
>`;
document.getElementById("documents-container").appendChild(div);
}
});
let logoutBtn = document.getElementById("logout");
logoutBtn.addEventListener("click", (e) => {
e.preventDefault();
auth
.signOut()
.then(function () {
window.location.replace("student-login.html");
})
.catch(function (error) {
console.error(error);
});
});
});