Skip to content

Commit 6830581

Browse files
committed
Product Comparison
1 parent 91275c9 commit 6830581

9 files changed

Lines changed: 574 additions & 284 deletions

File tree

backend/package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package-lock.json

Lines changed: 2 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/App.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ import PrivicyPolicy from './pages/PrivicyPolicy';
2323
import TermsAndServices from './pages/TermsAndServices';
2424
import SizeGuide from './pages/SizeGuide';
2525
import Contributors from './pages/Contributors';
26+
import { shopDataContext } from './context/ShopContext';
27+
import ComparisonPanel from './components/ComparisonPanel';
28+
import { RiPriceTag3Line } from "react-icons/ri";
2629

2730
function App() {
2831
const { userData } = useContext(userDataContext);
32+
const { compareList, comparePanelOpen, toggleComparePanel, removeFromCompare } = useContext(shopDataContext);
2933
const location = useLocation();
3034
const hideNavRoutes = ['/login', '/signup'];
3135
const shouldShowNav = !hideNavRoutes.includes(location.pathname);
@@ -195,6 +199,28 @@ function App() {
195199
<Route path='*' element={<NotFound />} />
196200
</Routes>
197201
<Ai />
202+
203+
{/* Global Comparison Floating Button */}
204+
{compareList.length > 0 && !comparePanelOpen && (
205+
<div className="fixed bottom-6 right-6 z-[100]">
206+
<button
207+
onClick={() => toggleComparePanel(true)}
208+
className="bg-cyan-500 hover:bg-cyan-400 text-white px-6 py-3 rounded-full shadow-lg shadow-cyan-500/30 flex items-center gap-2 transition-all hover:scale-105 border border-cyan-400/50 animate-bounce-short"
209+
>
210+
<RiPriceTag3Line className="text-xl" />
211+
<span className="font-bold">Compare ({compareList.length})</span>
212+
</button>
213+
</div>
214+
)}
215+
216+
{/* Global Comparison Panel */}
217+
{comparePanelOpen && (
218+
<ComparisonPanel
219+
compareList={compareList}
220+
onClose={() => toggleComparePanel(false)}
221+
removeProduct={removeFromCompare}
222+
/>
223+
)}
198224
</>
199225
);
200226
}

frontend/src/components/BestSeller.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ScrollTrigger } from 'gsap/ScrollTrigger';
99
gsap.registerPlugin(ScrollTrigger);
1010

1111
function BestSeller() {
12-
const { product } = useContext(shopDataContext);
12+
const { product, compareList, toggleCompare } = useContext(shopDataContext);
1313
const [bestseller, setBestseller] = useState([]);
1414
const sectionRef = useRef(null);
1515
const titleRef = useRef(null);
@@ -75,11 +75,11 @@ function BestSeller() {
7575
</div>
7676
<Title text1="BEST" text2="SELLERS" />
7777
</div>
78-
78+
7979
<p className="text-gray-400 mt-3 sm:mt-4 text-sm sm:text-base md:text-lg lg:text-xl max-w-xs sm:max-w-lg md:max-w-2xl mx-auto leading-relaxed px-2 sm:px-0">
8080
Discover our most loved products — tried, tested, and adored by thousands of customers worldwide.
8181
</p>
82-
82+
8383
<div className="mt-4 sm:mt-6 flex items-center justify-center gap-2 text-xs sm:text-sm text-amber-400">
8484
<div className="w-1.5 h-1.5 sm:w-2 sm:h-2 bg-amber-400 rounded-full animate-pulse"></div>
8585
<span>Trending now</span>
@@ -90,7 +90,7 @@ function BestSeller() {
9090
{bestseller.length > 0 ? (
9191
<div className="grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 sm:gap-4 md:gap-6 lg:gap-8">
9292
{bestseller.map((item, index) => (
93-
<div
93+
<div
9494
key={item._id}
9595
ref={el => cardsRef.current[index] = el}
9696
className="transform transition-all duration-500 hover:-translate-y-2"
@@ -102,6 +102,8 @@ function BestSeller() {
102102
image={item.image1}
103103
badge="BESTSELLER"
104104
badgeColor="from-red-500 to-orange-500"
105+
onCompare={() => toggleCompare(item)}
106+
isCompared={compareList?.some(p => p._id === item._id)}
105107
/>
106108
</div>
107109
))}

0 commit comments

Comments
 (0)