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 = `
`; + htmlz += `

No saved projects found.

`; + htmlz += `
`; + $("#error").append(htmlz); + } + }) + .catch((error) => { + console.log(error); + var htmlz = `
`; + htmlz += `

Failed to fetch data. Please try again later.

`; + htmlz += `
`; + $("#error").append(htmlz); + }); + }) + .catch((error) => { + console.log(error); + }); + } else { + // User is not logged in, handle accordingly + } + }); + }) + .catch((error) => { + console.log(error); + }); + +function loadData(data, db) { + var html = ""; + for (let i = data.length - 1; i >= 0; i--) { + try { + html += ` +
  • +
    +
    +

    ${data[i].langName}

    +
    + Project Admin: ${data[i].langAdmin} +
    ${data[i].langTitle}
    +
    +

    ${data[i].langDesc}

    +
    +
    + +
    + +
    +
    +
    +
  • + `; + } catch (error) { + console.log(error); + } + } + + $("#project").empty().append(html); + + + // Add event listener to share icons + const shareIcons = document.querySelectorAll('.share_icon'); + shareIcons.forEach(icon => { + icon.addEventListener('click', handleShareClick); + }); + + // Share icon click event handler + function handleShareClick(event) { + const url = event.target.dataset.url; + if (url) { + navigator.clipboard.writeText(url) + .then(() => { + alert('URL copied to clipboard:', url); + // You can show a success message or perform any other action here + }) + .catch((error) => { + console.log('Error copying URL to clipboard:', error); + // You can show an error message or perform any other action here + }); + } + } +} diff --git a/pages/saved.html b/pages/saved.html new file mode 100644 index 0000000..2d0e848 --- /dev/null +++ b/pages/saved.html @@ -0,0 +1,292 @@ + + + + + + + + + + + + + + + + Opentek | Saved Projects + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + +
    +
    +
    +
    +
    + + +
    +
    +
    + + + + + + + + + +
    +
    + +
    + +
    +
    + +
    +

    Theme Colors

    +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + \ No newline at end of file