-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
62 lines (52 loc) · 2.3 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Import Firebase Modules
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js";
import { getFirestore, collection, getDocs } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-firestore.js";
// Firebase Configuration from the Firestore database when we build the web app
// Replace with your API key and Configurations
const firebaseConfig = {
apiKey: "AIzaSyBOQOTpLHQLpR9_LqZmhrahUpdihNy6OEA",
authDomain: "menucard-25f3c.firebaseapp.com",
databaseURL: "https://menucard-25f3c-default-rtdb.firebaseio.com",
projectId: "menucard-25f3c",
storageBucket: "menucard-25f3c.firebasestorage.app",
messagingSenderId: "209194874363",
appId: "1:209194874363:web:7d178647acfd367bee875e",
measurementId: "G-GJTL9PZKGP"
};
// Initialize Firebase inorder to access the data from the firestore database
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
// Fetch and Display Customer Reviews from the firestore database
async function fetchReviews() {
const reviewsContainer = document.getElementById("reviewsContainer");
reviewsContainer.innerHTML = "<p>Loading reviews...</p>";
try {
const querySnapshot = await getDocs(collection(db, "Feedback"));
reviewsContainer.innerHTML = "";
if (querySnapshot.empty) {
reviewsContainer.innerHTML = "<p>No reviews available.</p>";
return;
}
querySnapshot.forEach((doc) => {
const data = doc.data();
const reviewCard = document.createElement("div");
reviewCard.classList.add("review-card");
reviewCard.innerHTML = `
<h3>${data.Name || "Anonymous"}</h3>
<p class="phone"> 📞${data.PhoneNumber || "N/A"}</p>
<p><strong>Review:</strong> ${data.Review || "No review provided."}</p>
`;
reviewsContainer.appendChild(reviewCard);
});
} catch (error) {
console.error("Error fetching reviews:", error);
reviewsContainer.innerHTML = "<p>Error loading reviews.</p>";
}
}
window.onload = fetchReviews;
document.addEventListener("DOMContentLoaded", () => {
const refreshBtn = document.getElementById("refreshBtn");
if (refreshBtn) {
refreshBtn.addEventListener("click", fetchReviews);
}
});