diff --git a/js/saved.js b/js/saved.js new file mode 100644 index 0000000..d8428c2 --- /dev/null +++ b/js/saved.js @@ -0,0 +1,118 @@ +const fetchAuthConfig = () => fetch("/auth_config.json"); + +// ... + +fetchAuthConfig() + .then((response) => response.json()) + .then((firebaseConfig) => { + firebase.initializeApp(firebaseConfig); + + const db = firebase.firestore(); + + firebase.auth().onAuthStateChanged((user) => { + if (user) { + const uid = user.uid; + console.log("UID:", uid); + + db.collection("users") + .doc(uid) + .get() + .then((userDoc) => { + const savedProjects = userDoc.data().saved || []; + console.log("Saved Projects:", savedProjects); + + const query = db.collection("projects").where("langId", "in", savedProjects); + + query.get() + .then((querySnapshot) => { + const data = []; + querySnapshot.forEach((doc) => { + data.push(doc.data()); + }); + + if (data.length > 0) { + $(function () { + loadData(data, db); + }); + } else { + // Handle case when no saved projects are found + var htmlz = `
No saved projects found.
`; + htmlz += `Failed to fetch data. Please try again later.
`; + htmlz += `Theme Colors
+ +