-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopupdates.js
41 lines (34 loc) · 1.23 KB
/
topupdates.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
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js";
import {
getDatabase,
ref,
push,
onValue,
} from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js";
var appSettings = {
databaseURL: "https://keepupnews-11dd1-default-rtdb.firebaseio.com/",
};
const app = initializeApp(appSettings);
const database = getDatabase(app);
// Define references
var reportNews = ref(database, "Report News");
onValue(reportNews, function (snapshot) {
let itemsArray = Object.values(snapshot.val());
console.log(itemsArray);
let imgArray = ["powerOutage.png", "roadClosure.png"];
for (let i = 0; i < itemsArray.length; i++) {
const card = document.createElement("div");
const timeSpan = document.createElement("span");
const image = document.createElement("img");
// Set content and attributes
timeSpan.textContent = itemsArray[i]["Date"];
image.src = imgArray[i];
// Append elements to card
card.appendChild(image); // Append image first
card.appendChild(document.createElement("br")); // Add a line break
card.appendChild(timeSpan);
// Add class to card
card.classList.add("card");
document.getElementById("updates").appendChild(card);
}
});