From 10f0469b56944826af171d1f87e2962d001b1fd0 Mon Sep 17 00:00:00 2001 From: Mann Patel <130435633+MannPatel0@users.noreply.github.com> Date: Sat, 12 Apr 2025 11:27:27 -0600 Subject: [PATCH] added review functionality --- backend/controllers/product.js | 1 + frontend/src/pages/Home.jsx | 24 ++++++ frontend/src/pages/ProductDetail.jsx | 108 +++++++-------------------- frontend/src/pages/Settings.jsx | 54 ++++++++++++++ recommondation-engine/app.py | 34 +++++++-- recommondation-engine/server.py | 7 +- 6 files changed, 139 insertions(+), 89 deletions(-) diff --git a/backend/controllers/product.js b/backend/controllers/product.js index c8f9885..b031c3f 100644 --- a/backend/controllers/product.js +++ b/backend/controllers/product.js @@ -14,6 +14,7 @@ exports.addToFavorite = async (req, res) => { success: true, message: "Product added to favorites successfully", }); + console.log(result); } catch (error) { console.error("Error adding favorite product:", error); return res.json({ error: "Could not add favorite product" }); diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index 92f3f3c..555744e 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -8,6 +8,29 @@ const Home = () => { const [recommended, setRecommended] = useState([]); const [history, sethistory] = useState([]); const [error, setError] = useState(null); + const storedUser = JSON.parse(sessionStorage.getItem("user")); + + const handleLinkClick = async (id) => { + // Example: append to localStorage or call analytics + const response = await fetch( + "http://localhost:3030/api/product/add_fav_product", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + userID: storedUser.ID, + productsID: id, + }), + }, + ); + + if (!response.ok) throw new Error("Failed to fetch products"); + + console.log(response); + console.log(`Add Product -> History: ${id}`); + }; useEffect(() => { const fetchrecomProducts = async () => { @@ -298,6 +321,7 @@ const Home = () => { handleLinkClick(listing.id)} className="bg-white border border-gray-200 hover:shadow-md transition-shadow w-70 flex-shrink-0 relative" >
diff --git a/frontend/src/pages/ProductDetail.jsx b/frontend/src/pages/ProductDetail.jsx index b64a998..b8dbc47 100644 --- a/frontend/src/pages/ProductDetail.jsx +++ b/frontend/src/pages/ProductDetail.jsx @@ -14,7 +14,7 @@ const ProductDetail = () => { reviews: null, }); const [isFavorite, setIsFavorite] = useState(false); - const [showContactForm, setShowContactForm] = useState(false); + const [contactForm, showContactForm, setShowContactForm] = useState(false); const [currentImage, setCurrentImage] = useState(0); const [reviews, setReviews] = useState([]); const [showReviewForm, setShowReviewForm] = useState(false); @@ -417,81 +417,15 @@ const ProductDetail = () => {

- - - {showContactForm && ( -
-

- Contact Seller -

-
-
- - -
-
- - -
-
- -