-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
discussion board backend
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |