Skip to content

Commit

Permalink
Discussion Working
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Sanderson committed Nov 14, 2024
1 parent b2485ff commit e3c2fa6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 54 deletions.
79 changes: 38 additions & 41 deletions public/scripts/clubSettings.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, updateDoc, getDocs, doc, query, where } from 'https://www.gstatic.com/firebasejs/10.13.2/firebase-firestore.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,
Expand Down Expand Up @@ -42,59 +42,56 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";

let docRef = await getClubdocRefFromQParams(queryParams);
console.log(docRef.id);
document.getElementById("club-name").placeholder = docRef.data()["BookClubName"];
document.getElementById("club-description").placeholder = docRef.data()["clubDescription"];


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

clubEditForm.addEventListener('submit', async function(e){
e.preventDefault();
let clubName = clubEditForm["club-name"].value;
let desc = clubEditForm["club-description"].value;
let joinCode = clubEditForm["club-joincode"].value;
if (desc == "")
let title = clubEditForm["currBook"].value;
let reading = clubEditForm["currentReading"].value;
let disc = clubEditForm["DiscTopic"].value;
if (title== "")
{
desc = docRef.data()["clubDescription"];
title = docRef.data()["clubBook"];
}
if (clubName == "")
if (reading == "")
{
clubName = docRef.data()["BookClubName"];
reading = docRef.data()["clubWeekReading"];
}
if (joinCode == "")
if (disc == "")
{
joincode = docRef.data()["JoinCode"];
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;
})

let bookClubsRef = collection(db, "BookClubs");
const q = query(bookClubsRef, where("BookClubName", "==", clubName));
const qsnap = await getDocs(q)

const q2 = query(bookClubsRef, where("JoinCode", "==", clubEditForm["club-joincode"].value));
const qsnap2 = await getDocs(q2);

let update = true;
// 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));
// }

if (!(qsnap.empty || clubName == docRef.data()["BookClubName"]))
{
update = false;
alert("Club Name Allready Exists")
}
if (!(qsnap2.empty || joinCode == docRef.data()["JoinCode"]))
{
update = false;
alert("Club Name Allready Exists")
}
// 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;
// })


if (update)
{
await updateDoc(doc(db,"BookClubs", docRef.id), {
BookClubName: clubName,
clubDescription: desc,
JoinCode: joinCode
}, clubName)

window.location.href = "./clubhomepage.html?id=" + docRef.id;
}
// }
})

20 changes: 10 additions & 10 deletions public/scripts/clubhome.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,7 @@ 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");
Expand Down Expand Up @@ -137,4 +129,12 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
})



if (await isAdmin(userUID) == 1)
{
document.getElementById("manage").href = "overview.html?id=" + docRef.id;
}
else
{
let elem = document.getElementById("manage")
elem.remove()
}
2 changes: 1 addition & 1 deletion public/scripts/manageclub.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
}
if (joinCode == "")
{
joincode = docRef.data()["JoinCode"];
joinCode = docRef.data()["JoinCode"];
}


Expand Down
14 changes: 12 additions & 2 deletions public/webpages/html/clubSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,25 @@ <h2>Edit Club Name and Description</h2>
<div class="form-group">
<label for="club-description">This Weeks Reading</label>
<textarea
id="current Reading"
id="currentReading"
placeholder=""
></textarea>
</div>
<div class="form-group">
<label for="club-name">Discussion Topic</label>
<input
type="text"
id="DiscTopic"
placeholder=""
value=""
/>
</div>
<div class="form-group">
<!-- <label>Clear Current Discussion?</label><input type="checkbox" id="del"/> </div> -->
<button type="submit" class="save-btn">Save Changes</button>
</form>
</main>
</div>
<script type="module" src="../../scripts/manageclub.js"></script>
<script>
// Function to change profile picture preview
function changeProfilePicture() {
Expand Down
1 change: 1 addition & 0 deletions public/webpages/html/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<a href="MyClubs.html"><button class="loginbutton">My Clubs</button></button></a>
<a href="club.html"><button class="loginbutton">Create A Club</button></button></a>
<a href="join.html"><button class="loginbutton">Join</button></a>
<a href="logout.html"><button class="loginbutton">Logout</button></a>
</li>


Expand Down

0 comments on commit e3c2fa6

Please sign in to comment.