From b2485ff40c5ed9ff97bcb0bd29d4e405dcae6d15 Mon Sep 17 00:00:00 2001
From: Ben Sanderson
Date: Wed, 13 Nov 2024 20:54:24 -0500
Subject: [PATCH] Discussion Posts functional mostly
---
public/scripts/clubhome.js | 40 +++++++-------
public/scripts/post.js | 69 ++++++++++++++++++++++++
public/webpages/html/clubhomepage.html | 2 +-
public/webpages/html/discussionpost.html | 25 +++++++++
4 files changed, 117 insertions(+), 19 deletions(-)
create mode 100644 public/scripts/post.js
create mode 100644 public/webpages/html/discussionpost.html
diff --git a/public/scripts/clubhome.js b/public/scripts/clubhome.js
index 8806b10..d9ef6e4 100644
--- a/public/scripts/clubhome.js
+++ b/public/scripts/clubhome.js
@@ -1,6 +1,6 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.13.2/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.13.2/firebase-analytics.js";
- import { getFirestore, collection, getDoc, getDocs, doc, query, where } from 'https://www.gstatic.com/firebasejs/10.13.2/firebase-firestore.js';
+ import { getFirestore, collection, orderBy, getDoc, getDocs, doc, query, where } from 'https://www.gstatic.com/firebasejs/10.13.2/firebase-firestore.js';
import { getAuth,
createUserWithEmailAndPassword,
signOut,
@@ -82,6 +82,7 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
+
async function getEmailFromUID(uid)
{
const q = query(collection(db, "Users"), where("uid", "==", uid));
@@ -90,6 +91,20 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
return qsnap.docs[0].data()["email"];
}
+ if (await isAdmin(userUID) == 1)
+ {
+ document.getElementById("manage").href = "overview.html?id=" + docRef.id;
+ }
+ else
+ {
+ let elem = document.getElementById("manage")
+ elem.remove()
+ }
+
+ const post = document.getElementById("post");
+ post.href = "discussionpost.html?id=" + queryParams.get("id");
+
+
let docRef = await getClubdocRefFromQParams(queryParams);
document.getElementById("clubName").textContent = "Welcome to the \"" + docRef.data()["BookClubName"] + "\" Book Club"
@@ -108,29 +123,18 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
parentUL.appendChild(newLI);
}
let docRef2 = doc(db,"BookClubs", queryParams.get("id"));
+
+ const discRef = collection(docRef2, "DiscussionPosts");
+ const dq = query(discRef, orderBy("postDate"));
+ const dqsnap = await getDocs(dq);
- const discRef = await getDocs(collection(docRef2, "DiscussionPosts"));
let elem;
- discRef.forEach((doc)=>{
+ dqsnap.forEach((doc)=>{
elem = createDisPost(doc);
document.getElementById("disc").appendChild(elem);
})
-
-
-
-
- console.log(isAdmin(userUID));
-
- if (await isAdmin(userUID) == 1)
- {
- document.getElementById("manage").href = "overview.html?id=" + docRef.id;
- }
- else
- {
- let elem = document.getElementById("manage")
- elem.remove()
- }
+
diff --git a/public/scripts/post.js b/public/scripts/post.js
new file mode 100644
index 0000000..70223d9
--- /dev/null
+++ b/public/scripts/post.js
@@ -0,0 +1,69 @@
+import { initializeApp } from "https://www.gstatic.com/firebasejs/10.13.2/firebase-app.js";
+ import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.13.2/firebase-analytics.js";
+ import { getFirestore, collection, orderBy, getDoc, addDoc, getDocs, doc, query, where } from 'https://www.gstatic.com/firebasejs/10.13.2/firebase-firestore.js';
+ import { getAuth,
+ createUserWithEmailAndPassword,
+signOut,
+signInWithEmailAndPassword,
+onAuthStateChanged
+ }
+
+from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
+ // TODO: Add SDKs for Firebase products that you want to use
+ // https://firebase.google.com/docs/web/setup#available-libraries
+
+ // Your web app's Firebase configuration
+ // For Firebase JS SDK v7.20.0 and later, measurementId is optional
+ const 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"
+ };
+
+ // Initialize Firebase
+ const app = initializeApp(firebaseConfig);
+ const analytics = getAnalytics(app);
+ const auth = getAuth();
+ const db = getFirestore(app);
+
+ const queryParams = new URLSearchParams(window.location.search);
+ let userUID = "";
+ let userEmail = "";
+ auth.onAuthStateChanged(function(user){
+ if (user) {
+ userUID = user.uid;
+ userEmail = user.email;
+ }
+ })
+
+const postform = document.getElementById("reply-form");
+
+postform.addEventListener("submit", async function (e) {
+
+ e.preventDefault();
+
+ let title = postform["title"].value;
+ let body = postform["text"].value;
+
+ //let docRef2 = doc(db,"BookClubs", queryParams.get("id"));
+ const discRef = collection(db,"BookClubs",queryParams.get("id"),"DiscussionPosts");
+
+ let docref = await addDoc(discRef, {
+ Author: userEmail,
+ Body: body,
+ Title: title,
+ postDate: new Date()
+ }).then((e)=>{
+ window.location.href = "./clubhomepage.html?id=" + queryParams.get("id");
+ })
+
+
+
+
+
+
+})
\ No newline at end of file
diff --git a/public/webpages/html/clubhomepage.html b/public/webpages/html/clubhomepage.html
index 23c379f..426f035 100644
--- a/public/webpages/html/clubhomepage.html
+++ b/public/webpages/html/clubhomepage.html
@@ -298,7 +298,7 @@ Discussion Board
Current Topic: None
-
+
+
+
+
+
+
diff --git a/public/webpages/html/discussionpost.html b/public/webpages/html/discussionpost.html
new file mode 100644
index 0000000..8c46c1e
--- /dev/null
+++ b/public/webpages/html/discussionpost.html
@@ -0,0 +1,25 @@
+
+
+