Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eunice homework4 #31

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"fetch": "^1.1.0"
}
}
Binary file added public/Images/action.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/adventure.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/bookclub1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/bookclub2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/bookclub3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/bookrecommendations1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/bookrecommendations2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/bookrecommendations3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/crime.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/drama.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/eigth8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/fantasy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/featuredbook9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/fiction.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/fifth5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/first1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/Images/fourth4.webp
Binary file not shown.
Binary file added public/Images/historical.jpg
Binary file added public/Images/logo.png
Binary file added public/Images/ninth9.jpg
Binary file added public/Images/non-fiction.jpg
Binary file added public/Images/romance.jpeg
Binary file added public/Images/second2.jpg
Binary file added public/Images/seventh7.jpeg
Binary file added public/Images/sixth6.jpg
Binary file added public/Images/tenth10.jpg
Binary file added public/Images/third3.jpg
Binary file added public/Images/trendinggroupdiscussion1.jpeg
Binary file added public/Images/trendinggroupdiscussion2.jpeg
Binary file added public/Images/trendinggroupdiscussion3.webp
Binary file not shown.
Binary file added public/Images/trendinggroupdiscussion4.jpeg
Binary file added public/Images/trendinggroupdiscussion5.jpeg
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
70 changes: 45 additions & 25 deletions public/scripts/auth1.js
Original file line number Diff line number Diff line change
@@ -1,5 +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, addDoc, setDoc, doc} from 'https://www.gstatic.com/firebasejs/10.13.2/firebase-firestore.js';
import { getAuth,
createUserWithEmailAndPassword,
signOut,
Expand Down Expand Up @@ -27,33 +28,45 @@ from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const auth = getAuth();


const db = getFirestore(app);
// signup form


const signupForm = document.querySelector("#signup-form");

if (signupForm != null)
{
signupForm.addEventListener('submit', function(e) {
e.preventDefault();
if (signupForm != null) {
signupForm.addEventListener('submit', function(e) {
e.preventDefault();

// Get user info
const email = signupForm["email"].value;
const password = signupForm["password"].value;

console.log(email, password);

// Sign up user
createUserWithEmailAndPassword(auth, email, password)
.then(cred => {
let user = cred.user;
return setDoc(doc(db, "Users", user.uid), {
email: user.email,
uid: user.uid
});
})
.then(() => {
alert("Account Creation Success");
window.location.href = "./dashboard.html";
})
.catch(error => {
console.error("Error: ", error);
alert("Error creating account: " + error.message);
});
});
}


// get user info
const email = signupForm["email"].value;
const password = signupForm["password"].value;

console.log(email, password);

// sign up user

createUserWithEmailAndPassword(auth, email,password).then(cred=>{
console.log(cred);
alert("Account Creation Success");
window.location.href = "./dashboard.html";
});
});
}

const loginForm = document.querySelector("#login-form");

Expand All @@ -66,7 +79,7 @@ if (loginForm != null)
const password = loginForm["password"].value;

signInWithEmailAndPassword(auth,email,password).then( cred=> {
console.log(cred);
console.log(cred);
window.signedinemail = email;
window.location.href = "./dashboard.html";
}
Expand All @@ -88,12 +101,19 @@ logout.addEventListener('click', (e)=>{
});
}

onAuthStateChanged(auth, (user)=>{
if (user){
document.querySelector("#user-email").textContent = user.email;
}
})





// addDoc(collection(db,"Users"),
// {
// email: user.email,
// uid: user.uid,
// clubs: []
// }).then(docref=>{
// console.log("Doc written with ID: ", docref.id);
// }).catch(error => {
// console.error("Error writing document: ", error);
// alert("Error creating account: " + error.message);
// })
File renamed without changes.
74 changes: 74 additions & 0 deletions public/scripts/clubhome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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 { 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);




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





async function getEmailFromUID(uid)
{
const q = query(collection(db, "Users"), where("uid", "==", uid));
const qsnap = await getDocs(q);

return qsnap.docs[0].data()["email"];
}

let docRef = await getClubdocRefFromQParams(queryParams);

document.getElementById("clubName").textContent = docRef.data()["BookClubName"]
document.getElementById("clubDescription").textContent = docRef.data()["clubDescription"]

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;


60 changes: 60 additions & 0 deletions public/scripts/clublist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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);

function appendElement (elemNode,textNode,href) {
var container = document.getElementById("listOfClubs");
var element = document.createElement(elemNode);
element.setAttribute("href","clubhomepage.html?id=" + href)
var text = document.createTextNode("\t" +textNode + "\n");
element.appendChild(text);
container.appendChild(element);
}


firebase.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 = ""

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"
};


console.log(user.uid);
})
}
else {
document.getElementById("clubs").textContent = "not signed in";
}});




52 changes: 52 additions & 0 deletions public/scripts/createClub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.13.2/firebase-app.js";
import { getAuth, onAuthStateChanged} from "https://www.gstatic.com/firebasejs/10.13.2/firebase-auth.js";
import { getFirestore, collection, getDoc,setDoc, getDocs, addDoc, 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"
};

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

const clubCreateForm = document.querySelector("#createClubForm");

auth.onAuthStateChanged(function(user){

clubCreateForm.addEventListener('submit', async function(e){
e.preventDefault();
const clubName = clubCreateForm["clubname"].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"), {
BookClubName: clubName,
ClubUsers: [user.uid],
clubDescription: "no description"
}, clubName)

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

}
else{
alert("Club Name Allready Exists")
}



})
});
13 changes: 13 additions & 0 deletions public/scripts/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


export async function getClubDocFromQParams(queryParams)
{
const q = query(collection(db, "BookClubs"), where("BookClubName", "==", queryParams.get("name")));
const qsnap = await getDocs(q);


const docData = qsnap.docs[0].data();
console.log(docData)
console.log(docData["BookClubName"]);
return docData;
}
Loading