From bd9345e1d9fb8dd70033e4eb2e0a58936fee16e8 Mon Sep 17 00:00:00 2001 From: Saloni Atole Date: Thu, 11 Jul 2024 23:02:04 +0530 Subject: [PATCH] wishlist page added --- client/package-lock.json | 17 ++++++- client/package.json | 3 +- client/src/App.jsx | 4 ++ client/src/pages/Wishlist/wishlist.jsx | 62 ++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 client/src/pages/Wishlist/wishlist.jsx diff --git a/client/package-lock.json b/client/package-lock.json index 2e8f6db..3874746 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -18,7 +18,8 @@ "react-razorpay": "^2.0.1", "react-redux": "^8.1.2", "react-router-dom": "^6.16.0", - "redux-persist": "^6.0.0" + "redux-persist": "^6.0.0", + "uuid": "^10.0.0" }, "devDependencies": { "@types/react": "^18.2.15", @@ -1046,7 +1047,7 @@ "version": "18.2.8", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.8.tgz", "integrity": "sha512-bAIvO5lN/U8sPGvs1Xm61rlRHHaq5rp5N3kp9C+NJ/Q41P8iqjkXSu0+/qu8POsjH9pNWb0OYabFez7taP7omw==", - "devOptional": true, + "dev": true, "dependencies": { "@types/react": "*" } @@ -4801,6 +4802,18 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, + "node_modules/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vite": { "version": "4.4.9", "resolved": "https://registry.npmjs.org/vite/-/vite-4.4.9.tgz", diff --git a/client/package.json b/client/package.json index 1db4ae2..4db3662 100644 --- a/client/package.json +++ b/client/package.json @@ -20,7 +20,8 @@ "react-razorpay": "^2.0.1", "react-redux": "^8.1.2", "react-router-dom": "^6.16.0", - "redux-persist": "^6.0.0" + "redux-persist": "^6.0.0", + "uuid": "^10.0.0" }, "devDependencies": { "@types/react": "^18.2.15", diff --git a/client/src/App.jsx b/client/src/App.jsx index 300aac8..4c80b1a 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -14,6 +14,8 @@ import Retailer_home from "./pages/Retailer-home"; import Product from "./pages/Product"; import Cart from "./pages/Cart"; import ScrollToTop from "./components/ScrollToTop"; +import Wishlist from "./pages/Wishlist/wishlist"; +import './App.css' function App() { return ( @@ -30,7 +32,9 @@ function App() { } /> } /> } /> + } /> }> + } /> diff --git a/client/src/pages/Wishlist/wishlist.jsx b/client/src/pages/Wishlist/wishlist.jsx new file mode 100644 index 0000000..f42ad70 --- /dev/null +++ b/client/src/pages/Wishlist/wishlist.jsx @@ -0,0 +1,62 @@ +// src/components/Wishlist.js +import React, { useState } from 'react'; +import { v4 as uuidv4 } from 'uuid'; // For generating unique keys + +const Wishlist = () => { + const [wishlist, setWishlist] = useState([]); + + const addToWishlist = (product) => { + if (!wishlist.some(item => item.id === product.id)) { + setWishlist(prevWishlist => [...prevWishlist, { ...product, id: uuidv4() }]); + } + }; + + const removeFromWishlist = (productId) => { + setWishlist(prevWishlist => prevWishlist.filter(item => item.id !== productId)); + }; + + const products = [ + { id: uuidv4(), name: 'Running Shoes' }, + { id: uuidv4(), name: 'Basketball Shoes' }, + { id: uuidv4(), name: 'Casual Shoes' }, + ]; + + return ( +
+

Wishlist

+
+ {products.map(product => ( +
+ {product.name} + +
+ ))} +
+

My Wishlist

+ {wishlist.length === 0 ? ( +

No items in wishlist

+ ) : ( +
    + {wishlist.map(item => ( +
  • + {item.name} + +
  • + ))} +
+ )} +
+ ); +}; + +export default Wishlist;