Skip to content

Commit

Permalink
mydiscussions
Browse files Browse the repository at this point in the history
discussion board backend
  • Loading branch information
UmarA2002 committed Oct 24, 2024
1 parent 7abbf8b commit 0e8dd74
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
51 changes: 51 additions & 0 deletions public/scripts/discussion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.13.2/firebase-app.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
import { getFirestore, collection, getDoc, getDocs, doc, query, where } from 'https://www.gstatic.com/firebasejs/10.13.2/firebase-firestore.js';

// Initialize Firebase
var firebaseConfig = {
apiKey: "AIzaSyAt-SInlPaL2FzwtXrRltIEiV5l8k5HMjg",
authDomain: "pageturners-a831a.firebaseapp.com",
projectId: "pageturners-a831a",
storageBucket: "pageturners-a831a.appspot.com",
messagingSenderId: "304224952392",
appId: "1:304224952392:web:f33dbc84b481e39a44787d",
measurementId: "G-C6DKQSJ1R8"
};

firebase.initializeApp(firebaseConfig);
const app = initializeApp(firebaseConfig);
const auth = getAuth();
const db = getFirestore(app);

//get HTML element for display
let myDiscussions = document.getElementById('myDiscussions');
//store snapshot in each element of list
function getDiscussions() {
const dbRef = ref(db)
get(child(dbRef, "discussions"))
.then((snapshot)=>{
var allDiscussions = [];
snapshot.forEach(childSnapshot =>{
allDiscussions.push(childSnapshot.val()).then((discussions)=>{
discussions.forEach(entry =>{addEntryToList(entry)})
}
);
});

});

}
//creating a list, adding entries
function addEntryToList(entry){
let value = entry.val();

let replies = document.createElement('li');
replies.innerHTML = "replies: " + value.replies;

let list = document.createElement('ul');
list.append(replies);
myDiscussions.append(list);
}
//event to force function
window.addEventListener('load',getDiscussions );
20 changes: 20 additions & 0 deletions public/webpages/css/mydiscussions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Montserrat", sans-serif;
}

body {
background-color: #f4f4f4;
color: #333;
}

.my-discussions {
background-color: #ffae66;
color: #333;
text-align:center;
font-size:14px;

}

17 changes: 17 additions & 0 deletions public/webpages/html/mydiscussions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="../css/mydiscussions.css" />
<body id="body">
<ul id="my-discussions">

</ul>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
<script defer type="module" src="../../scripts/discussion.js"> </script>
</body>
</html>

0 comments on commit 0e8dd74

Please sign in to comment.