Skip to content

Commit 229ecdc

Browse files
committed
Firebase changes
adding javasciript
1 parent 2f93f4f commit 229ecdc

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

js/firebase.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
2+
import { getFirestore } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
3+
4+
const firebaseConfig = {
5+
apiKey: "AIzaSyCUHWXemBpfAWOSDqj1_rY6s4oQr27FnKg",
6+
authDomain: "noctive-41c22.firebaseapp.com",
7+
projectId: "noctive-41c22",
8+
storageBucket: "noctive-41c22.firebasestorage.app",
9+
messagingSenderId: "617642134193",
10+
appId: "1:617642134193:web:ea5f0c93e56c654f66f090",
11+
measurementId: "G-8ZFW3MTB3C"
12+
};
13+
14+
const app = initializeApp(firebaseConfig);
15+
const db = getFirestore(app);
16+
17+
export { db };

js/main.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { db } from "./firebase.js";
2+
import {
3+
collection,
4+
getDocs
5+
} from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
6+
7+
async function loadPosts() {
8+
const container = document.getElementById("firebasePosts");
9+
10+
if (!container) return;
11+
12+
container.innerHTML = "Loading...";
13+
14+
try {
15+
const querySnapshot = await getDocs(collection(db, "Posts"));
16+
17+
container.innerHTML = "";
18+
19+
querySnapshot.forEach((doc) => {
20+
const data = doc.data();
21+
22+
const div = document.createElement("div");
23+
div.textContent = data.text;
24+
25+
container.appendChild(div);
26+
});
27+
28+
} catch (err) {
29+
console.error(err);
30+
container.innerHTML = "Error loading posts";
31+
}
32+
}
33+
34+
document.addEventListener("DOMContentLoaded", loadPosts);

pages/home.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,8 @@
23812381

23822382
setAuthMode(true);
23832383
</script>
2384+
<div id="firebasePosts"></div>
2385+
<script type="module" src="../js/main.js"></script>
23842386
</body>
23852387
</html>
23862388

0 commit comments

Comments
 (0)