Skip to content

Commit

Permalink
Merge branch 'Sanderson_Sprint3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Sanderson committed Nov 14, 2024
2 parents 54726d8 + e3c2fa6 commit 7e39b74
Show file tree
Hide file tree
Showing 23 changed files with 1,519 additions and 95 deletions.
4 changes: 4 additions & 0 deletions public/TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

-join from link

-allow changin of join code
2 changes: 2 additions & 0 deletions public/scripts/club.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ function loadProfilePicture() {

// Load the profile picture when the page is loaded
window.onload = loadProfilePicture;


97 changes: 97 additions & 0 deletions public/scripts/clubSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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, deleteDoc, addDoc, collection, getDoc, updateDoc, 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);

async function getClubdocRefFromQParams(queryParams)
{
let docRef = doc(db,"BookClubs",queryParams.get("id"));
const docSnap = await getDoc(docRef);
console.log(docSnap.data());
return docSnap;
}

const queryParams = new URLSearchParams(window.location.search);

let docRef = await getClubdocRefFromQParams(queryParams);
console.log(docRef.id);

const clubEditForm = document.getElementById("clubmanage");

clubEditForm.addEventListener('submit', async function(e){
e.preventDefault();
let title = clubEditForm["currBook"].value;
let reading = clubEditForm["currentReading"].value;
let disc = clubEditForm["DiscTopic"].value;
if (title== "")
{
title = docRef.data()["clubBook"];
}
if (reading == "")
{
reading = docRef.data()["clubWeekReading"];
}
if (disc == "")
{
disc = docRef.data()["discussionTopic"];
}

await updateDoc(doc(db,"BookClubs", docRef.id), {
clubBook: title,
clubWeekReading: reading,
discussionTopic: disc
}, title).then(()=>
{
window.location.href = "./clubhomepage.html?id=" + docRef.id;
})

// if (clubEditForm["del"].value == "on")
// {

// let discRef = collection(db,"BookClubs", docRef.id, "DiscussionPosts");
// const dq = query(discRef);
// const dqsnap = await getDocs(dq);

// for (const docu in dq)
// {
// await deleteDoc(doc(db,"BookClubs", docu.id, "DiscussionPosts",docu.id));
// }

// addDoc(disccol, {Title: "Club Discussion Was Cleared",
// Body: "At the time of this post the club discussion board was cleared",
// Author: "PageTurners Team",
// postDate: new Date()}).then((e)=>{
// window.location.href = "./clubhomepage.html?id=" + docRef.id;
// })


// }
})

84 changes: 75 additions & 9 deletions public/scripts/clubhome.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -31,9 +31,46 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
const db = getFirestore(app);

const queryParams = new URLSearchParams(window.location.search);
let userUID = "";
auth.onAuthStateChanged(function(user){
if (user) {
userUID = user.uid;
}
})

function createDisPost(docRef)
{
const li = document.createElement("li")
const p1 = document.createElement("p")
const p2 = document.createElement("p");
const p3 = document.createElement("p");
const small = document.createElement("small");

p1.textContent = docRef.data()["Title"];
p1.setAttribute("class","bold underline");
p2.textContent = "By: " + docRef.data()["Author"];
p2.setAttribute("class","bold")
p3.textContent = docRef.data()["Body"];
small.textContent = docRef.data()["postDate"].toDate();

li.appendChild(p1);
li.appendChild(p2);
li.appendChild(p3);
li.appendChild(small);

return li;

}


async function isAdmin(userUID)
{
const docRef = await getClubdocRefFromQParams(new URLSearchParams(window.location.search));
if (docRef.data()["ClubAdmins"].includes(userUID))
{
return 1;
}
return 0;
}

async function getClubdocRefFromQParams(queryParams)
{
Expand All @@ -46,7 +83,6 @@ 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));
Expand All @@ -55,20 +91,50 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
return qsnap.docs[0].data()["email"];
}



const post = document.getElementById("post");
post.href = "discussionpost.html?id=" + queryParams.get("id");


let docRef = await getClubdocRefFromQParams(queryParams);

document.getElementById("clubName").textContent = docRef.data()["BookClubName"]
document.getElementById("clubName").textContent = "Welcome to the \"" + docRef.data()["BookClubName"] + "\" Book Club"
document.getElementById("clubDescription").textContent = docRef.data()["clubDescription"]
document.getElementById("booktitle").textContent = docRef.data()["clubBook"];
document.getElementById("bookdesc").textContent = docRef.data()["clubWeekReading"];
document.getElementById("disctopic").textContent = "Current Discussion Topic: " + docRef.data()["discussionTopic"]
const parentUL = document.getElementById("members");


for (const uid of docRef.data()["ClubUsers"])
{
const newLI = document.createElement("li");
newLI.textContent = await getEmailFromUID(uid);

const parentUL = document.getElementById("members");
parentUL.appendChild(newLI);
}

document.getElementById("manage").href = "overview.html?id=" + docRef.id;


let docRef2 = doc(db,"BookClubs", queryParams.get("id"));

const discRef = collection(docRef2, "DiscussionPosts");
const dq = query(discRef, orderBy("postDate"));
const dqsnap = await getDocs(dq);

let elem;

dqsnap.forEach((doc)=>{

elem = createDisPost(doc);
document.getElementById("disc").appendChild(elem);
})


if (await isAdmin(userUID) == 1)
{
document.getElementById("manage").href = "overview.html?id=" + docRef.id;
}
else
{
let elem = document.getElementById("manage")
elem.remove()
}
61 changes: 51 additions & 10 deletions public/scripts/clublist.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var firebaseConfig = {
measurementId: "G-C6DKQSJ1R8"
};

firebase.initializeApp(firebaseConfig);

const app = initializeApp(firebaseConfig);
const auth = getAuth();
const db = getFirestore(app);
Expand All @@ -27,27 +27,68 @@ function appendElement (elemNode,textNode,href) {
container.appendChild(element);
}

function createBookClubElem(doc)
{
let a = document.createElement("a")
let div = document.createElement("div");
let h3 = document.createElement("h3");
let p = document.createElement("p")

a.href = "./clubhomepage.html?id=" + doc.id;
h3.textContent = doc.data()["BookClubName"];
p.textContent = doc.data()["clubDescription"];
div.setAttribute("class","book-club-item");
div.appendChild(h3);
div.appendChild(p);
a.appendChild(div);

return a;

}
function createBookClubElemNoLink(doc)
{

let div = document.createElement("div");
let h3 = document.createElement("h3");
let p = document.createElement("p")

firebase.auth().onAuthStateChanged(function(user){

h3.textContent = doc.data()["BookClubName"];
p.textContent = doc.data()["clubDescription"];
div.setAttribute("class","book-club-item");
div.appendChild(h3);
div.appendChild(p);


return div;

}

auth.onAuthStateChanged(function(user){
if (user) {
const docRef = doc(db, "Users", user.uid);
const docSnap = getDoc(docRef);
const q = query(collection(db, "BookClubs"), where("ClubUsers", "array-contains", user.uid));
const qSnap = getDocs(q).then((snapshot)=>
{
let output = ""
const clublist = document.getElementById("list2");

for (const doc of snapshot.docs)
{

appendElement("a",doc.data()["BookClubName"], doc.id);
appendElement("p", "\n", "none")
// output+="\n<a href=\"clubhomepage?" + doc.data()["BookClubName"] +"\" >";
// output+= doc.data()["BookClubName"];
// output+= "</a>\n"
clublist.appendChild(createBookClubElem(doc));

};
const q2 = query(collection(db, "BookClubs"), where("ClubUsersUnaccepted", "array-contains", user.uid));
const qsnap = getDocs(q2).then((snapshot)=>
{
const clublist2 = document.getElementById("list1");


for (const doc of snapshot.docs)
{
clublist2.appendChild(createBookClubElemNoLink(doc))
}
})
console.log(user.uid);
})
}
Expand Down
25 changes: 20 additions & 5 deletions public/scripts/createClub.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,34 @@ auth.onAuthStateChanged(function(user){
clubCreateForm.addEventListener('submit', async function(e){
e.preventDefault();
const clubName = clubCreateForm["clubname"].value;

const joinCode = clubCreateForm["joincode"].value;
let bookClubsRef = collection(db, "BookClubs");
const q = query(bookClubsRef, where("BookClubName", "==", clubName));
const qsnap = await getDocs(q)



if (qsnap.empty){
await addDoc(collection(db,"BookClubs"), {
const docRef = await addDoc(collection(db,"BookClubs"), {
BookClubName: clubName,
ClubUsers: [user.uid],
clubDescription: "no description"
}, clubName)
ClubUsersUnaccepted: [],
ClubOwner: user.uid,
ClubAdmins: [user.uid],
JoinCode: joinCode,
clubDescription: "no description",
clubBook: "No Current Book",
clubWeekReading: "No Reading for this Week",
discussionTopic: "No Current Discussion Topic"
}, clubName);

const subColl = collection(docRef, "DiscussionPosts");

addDoc(subColl, {Title: "Congratulations on Club Creation",
Body: "We hope you enjoy your new book club! Happy Reading :)",
Author: "PageTurners Team",
postDate: new Date()})

window.location.href = "./dashboard.html";

}
Expand All @@ -49,4 +63,5 @@ auth.onAuthStateChanged(function(user){


})
});
});

Loading

0 comments on commit 7e39b74

Please sign in to comment.