diff --git a/src/App.js b/src/App.js
index e1b2110..40fb5f7 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,4 +1,4 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
import './App.css';
import Header from './components/Header';
import ProductList from './components/ProductList';
@@ -11,72 +11,60 @@ import ArtDecor from './pages/ArtDecor';
import Collectibles from './pages/Collectibles';
import About from './pages/About';
-class App extends Component {
- constructor(props) {
- super(props);
- this.state = {
- cartItems: [],
- isCartOpen: false,
- searchTerm: '',
- currentPage: 'home'
- };
- }
+const App = () => {
+ const [cartItems, setCartItems] = useState([]);
+ const [isCartOpen, setIsCartOpen] = useState(false);
+ const [searchTerm, setSearchTerm] = useState('');
+ const [currentPage, setCurrentPage] = useState('home');
- handleAddToCart = (product) => {
- const existingItem = this.state.cartItems.find(item => item.id === product.id);
+ const handleAddToCart = (product) => {
+ const existingItem = cartItems.find(item => item.id === product.id);
if (existingItem) {
- this.setState({
- cartItems: this.state.cartItems.map(item =>
- item.id === product.id
- ? { ...item, quantity: item.quantity + 1 }
- : item
- )
- });
+ setCartItems(cartItems.map(item =>
+ item.id === product.id
+ ? { ...item, quantity: item.quantity + 1 }
+ : item
+ ));
} else {
- this.setState({
- cartItems: [...this.state.cartItems, { ...product, quantity: 1 }]
- });
+ setCartItems([...cartItems, { ...product, quantity: 1 }]);
}
- }
+ };
- handleRemoveFromCart = (productId) => {
- this.setState({
- cartItems: this.state.cartItems.filter(item => item.id !== productId)
- });
- }
+ const handleRemoveFromCart = (productId) => {
+ setCartItems(cartItems.filter(item => item.id !== productId));
+ };
- handleUpdateQuantity = (productId, newQuantity) => {
- this.setState({
- cartItems: this.state.cartItems.map(item =>
- item.id === productId
- ? { ...item, quantity: newQuantity }
- : item
- )
- });
- }
+ const handleUpdateQuantity = (productId, newQuantity) => {
+ setCartItems(cartItems.map(item =>
+ item.id === productId
+ ? { ...item, quantity: newQuantity }
+ : item
+ ));
+ };
- handleCartToggle = () => {
- this.setState({ isCartOpen: !this.state.isCartOpen });
- }
+ const handleCartToggle = () => {
+ setIsCartOpen(!isCartOpen);
+ };
- handleSearch = (searchTerm) => {
- this.setState({ searchTerm, currentPage: 'products' });
- }
+ const handleSearch = (searchTerm) => {
+ setSearchTerm(searchTerm);
+ setCurrentPage('products');
+ };
- handleNavigation = (page) => {
- this.setState({ currentPage: page, searchTerm: '' });
- }
+ const handleNavigation = (page) => {
+ setCurrentPage(page);
+ setSearchTerm('');
+ };
- getCartItemCount = () => {
- return this.state.cartItems.reduce((total, item) => total + item.quantity, 0);
- }
+ const getCartItemCount = () => {
+ return cartItems.reduce((total, item) => total + item.quantity, 0);
+ };
- renderCurrentPage = () => {
- const { currentPage, searchTerm } = this.state;
+ const renderCurrentPage = () => {
const commonProps = {
- onAddToCart: this.handleAddToCart,
- onNavigate: this.handleNavigation
+ onAddToCart: handleAddToCart,
+ onNavigate: handleNavigation
};
switch (currentPage) {
@@ -96,40 +84,37 @@ class App extends Component {
default:
return (
);
}
- }
-
- render() {
+ };
return (
- {this.renderCurrentPage()}
+ {renderCurrentPage()}
);
- }
-}
+};
export default App;
diff --git a/src/components/Cart.js b/src/components/Cart.js
index 78d132e..9862619 100644
--- a/src/components/Cart.js
+++ b/src/components/Cart.js
@@ -1,46 +1,33 @@
-import React, { Component } from 'react';
+import React, { useEffect } from 'react';
-class Cart extends Component {
- constructor(props) {
- super(props);
- this.state = {
- isOpen: false
- };
- }
+const Cart = ({ cartItems, isOpen, onClose, onRemoveFromCart, onUpdateQuantity }) => {
+ useEffect(() => {
+ }, [isOpen]);
- componentDidUpdate(prevProps) {
- if (prevProps.isOpen !== this.props.isOpen) {
- this.setState({ isOpen: this.props.isOpen });
+ const handleRemoveItem = (productId) => {
+ if (onRemoveFromCart) {
+ onRemoveFromCart(productId);
}
- }
+ };
- handleRemoveItem = (productId) => {
- if (this.props.onRemoveFromCart) {
- this.props.onRemoveFromCart(productId);
- }
- }
-
- handleUpdateQuantity = (productId, newQuantity) => {
+ const handleUpdateQuantity = (productId, newQuantity) => {
if (newQuantity <= 0) {
- this.handleRemoveItem(productId);
- } else if (this.props.onUpdateQuantity) {
- this.props.onUpdateQuantity(productId, newQuantity);
+ handleRemoveItem(productId);
+ } else if (onUpdateQuantity) {
+ onUpdateQuantity(productId, newQuantity);
}
- }
+ };
- calculateTotal = () => {
- return this.props.cartItems.reduce((total, item) => {
+ const calculateTotal = () => {
+ return cartItems.reduce((total, item) => {
return total + (item.price * item.quantity);
}, 0);
- }
+ };
- handleCheckout = () => {
+ const handleCheckout = () => {
alert('Thank you for your interest! Checkout functionality would be implemented here.');
- }
-
- render() {
- const { cartItems, isOpen, onClose } = this.props;
- const total = this.calculateTotal();
+ };
+ const total = calculateTotal();
if (!isOpen) return null;
@@ -74,21 +61,21 @@ class Cart extends Component {
this.handleUpdateQuantity(item.id, item.quantity - 1)}
+ onClick={() => handleUpdateQuantity(item.id, item.quantity - 1)}
className="quantity-btn"
>
-
{item.quantity}
this.handleUpdateQuantity(item.id, item.quantity + 1)}
+ onClick={() => handleUpdateQuantity(item.id, item.quantity + 1)}
className="quantity-btn"
>
+
this.handleRemoveItem(item.id)}
+ onClick={() => handleRemoveItem(item.id)}
className="remove-btn"
>
Remove
@@ -108,7 +95,7 @@ class Cart extends Component {
Proceed to Checkout
@@ -122,7 +109,6 @@ class Cart extends Component {
);
- }
-}
+};
export default Cart;
diff --git a/src/components/Footer.js b/src/components/Footer.js
index 6a0dde6..32b709e 100644
--- a/src/components/Footer.js
+++ b/src/components/Footer.js
@@ -1,29 +1,23 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
-class Footer extends Component {
- constructor(props) {
- super(props);
- this.state = {
- email: '',
- subscribed: false
- };
- }
+const Footer = () => {
+ const [email, setEmail] = useState('');
+ const [subscribed, setSubscribed] = useState(false);
- handleEmailChange = (e) => {
- this.setState({ email: e.target.value });
- }
+ const handleEmailChange = (e) => {
+ setEmail(e.target.value);
+ };
- handleNewsletterSubmit = (e) => {
+ const handleNewsletterSubmit = (e) => {
e.preventDefault();
- if (this.state.email) {
- this.setState({ subscribed: true, email: '' });
+ if (email) {
+ setSubscribed(true);
+ setEmail('');
setTimeout(() => {
- this.setState({ subscribed: false });
+ setSubscribed(false);
}, 3000);
}
- }
-
- render() {
+ };
const currentYear = new Date().getFullYear();
return (
@@ -64,12 +58,12 @@ class Footer extends Component {
Newsletter
Stay updated with our latest finds and exclusive offers.
-
- {this.state.subscribed && (
+ {subscribed && (
Thank you for subscribing!
)}
@@ -95,7 +89,6 @@ class Footer extends Component {
);
- }
-}
+};
export default Footer;
diff --git a/src/components/Header.js b/src/components/Header.js
index 136c6f3..d020910 100644
--- a/src/components/Header.js
+++ b/src/components/Header.js
@@ -1,33 +1,25 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
-class Header extends Component {
- constructor(props) {
- super(props);
- this.state = {
- searchTerm: ''
- };
- }
+const Header = ({ cartItemCount, onCartClick, onSearch, onNavigate, currentPage }) => {
+ const [searchTerm, setSearchTerm] = useState('');
- handleSearchChange = (e) => {
- this.setState({ searchTerm: e.target.value });
- }
+ const handleSearchChange = (e) => {
+ setSearchTerm(e.target.value);
+ };
- handleSearchSubmit = (e) => {
+ const handleSearchSubmit = (e) => {
e.preventDefault();
- if (this.props.onSearch) {
- this.props.onSearch(this.state.searchTerm);
+ if (onSearch) {
+ onSearch(searchTerm);
}
- }
+ };
- handleNavClick = (e, page) => {
+ const handleNavClick = (e, page) => {
e.preventDefault();
- if (this.props.onNavigate) {
- this.props.onNavigate(page);
+ if (onNavigate) {
+ onNavigate(page);
}
- }
-
- render() {
- const { cartItemCount, onCartClick, currentPage } = this.props;
+ };
return (
);
- }
-}
+};
export default Header;
diff --git a/src/components/ProductCard.js b/src/components/ProductCard.js
index 15d845e..82d5e71 100644
--- a/src/components/ProductCard.js
+++ b/src/components/ProductCard.js
@@ -1,36 +1,27 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
-class ProductCard extends Component {
- constructor(props) {
- super(props);
- this.state = {
- isHovered: false
- };
- }
+const ProductCard = ({ product, onAddToCart }) => {
+ const [isHovered, setIsHovered] = useState(false);
- handleMouseEnter = () => {
- this.setState({ isHovered: true });
- }
+ const handleMouseEnter = () => {
+ setIsHovered(true);
+ };
- handleMouseLeave = () => {
- this.setState({ isHovered: false });
- }
+ const handleMouseLeave = () => {
+ setIsHovered(false);
+ };
- handleAddToCart = () => {
- if (this.props.onAddToCart) {
- this.props.onAddToCart(this.props.product);
+ const handleAddToCart = () => {
+ if (onAddToCart) {
+ onAddToCart(product);
}
- }
-
- render() {
- const { product } = this.props;
- const { isHovered } = this.state;
+ };
return (
{product.inStock ? 'Add to Cart' : 'Sold Out'}
@@ -76,7 +67,6 @@ class ProductCard extends Component {
);
- }
-}
+};
export default ProductCard;
diff --git a/src/components/ProductList.js b/src/components/ProductList.js
index 5d94b18..a934942 100644
--- a/src/components/ProductList.js
+++ b/src/components/ProductList.js
@@ -1,13 +1,10 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
import ProductCard from './ProductCard';
-class ProductList extends Component {
- constructor(props) {
- super(props);
- this.state = {
- sortBy: 'name',
- filterBy: 'all',
- products: [
+const ProductList = ({ onAddToCart, searchTerm }) => {
+ const [sortBy, setSortBy] = useState('name');
+ const [filterBy, setFilterBy] = useState('all');
+ const [products] = useState([
{
id: 1,
name: "Victorian Mahogany Writing Desk",
@@ -88,23 +85,22 @@ class ProductList extends Component {
category: "jewelry"
}
]
- };
- }
+ );
- handleSortChange = (e) => {
- this.setState({ sortBy: e.target.value });
- }
+ const handleSortChange = (e) => {
+ setSortBy(e.target.value);
+ };
- handleFilterChange = (e) => {
- this.setState({ filterBy: e.target.value });
- }
+ const handleFilterChange = (e) => {
+ setFilterBy(e.target.value);
+ };
- getSortedAndFilteredProducts = () => {
- let filteredProducts = this.state.products;
+ const getSortedAndFilteredProducts = () => {
+ let filteredProducts = products;
// Apply search filter if provided
- if (this.props.searchTerm) {
- const searchLower = this.props.searchTerm.toLowerCase();
+ if (searchTerm) {
+ const searchLower = searchTerm.toLowerCase();
filteredProducts = filteredProducts.filter(product =>
product.name.toLowerCase().includes(searchLower) ||
product.description.toLowerCase().includes(searchLower) ||
@@ -113,15 +109,15 @@ class ProductList extends Component {
}
// Apply category filter
- if (this.state.filterBy !== 'all') {
+ if (filterBy !== 'all') {
filteredProducts = filteredProducts.filter(product =>
- product.category === this.state.filterBy
+ product.category === filterBy
);
}
// Apply sorting
filteredProducts.sort((a, b) => {
- switch (this.state.sortBy) {
+ switch (sortBy) {
case 'price-low':
return a.price - b.price;
case 'price-high':
@@ -135,11 +131,9 @@ class ProductList extends Component {
});
return filteredProducts;
- }
+ };
- render() {
- const { onAddToCart } = this.props;
- const products = this.getSortedAndFilteredProducts();
+ const filteredProducts = getSortedAndFilteredProducts();
return (
@@ -150,8 +144,8 @@ class ProductList extends Component {
Filter by Category:
All Categories
Furniture
@@ -165,8 +159,8 @@ class ProductList extends Component {
Sort by:
Name
Price: Low to High
@@ -178,8 +172,8 @@ class ProductList extends Component {
- {products.length > 0 ? (
- products.map(product => (
+ {filteredProducts.length > 0 ? (
+ filteredProducts.map(product => (
);
- }
-}
+};
export default ProductList;
diff --git a/src/pages/ArtDecor.js b/src/pages/ArtDecor.js
index bcfe5f7..59fa7f1 100644
--- a/src/pages/ArtDecor.js
+++ b/src/pages/ArtDecor.js
@@ -1,11 +1,8 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
import ProductCard from '../components/ProductCard';
-class ArtDecor extends Component {
- constructor(props) {
- super(props);
- this.state = {
- artProducts: [
+const ArtDecor = ({ onAddToCart }) => {
+ const [artProducts] = useState([
{
id: 3,
name: "Ming Dynasty Porcelain Vase",
@@ -85,11 +82,7 @@ class ArtDecor extends Component {
category: "art"
}
]
- };
- }
-
- render() {
- const { onAddToCart } = this.props;
+ );
return (
@@ -134,7 +127,7 @@ class ArtDecor extends Component {
Available Art & Decor
- {this.state.artProducts.map(product => (
+ {artProducts.map(product => (
);
- }
-}
+};
export default ArtDecor;
diff --git a/src/pages/Furniture.js b/src/pages/Furniture.js
index defaf44..7a2ab41 100644
--- a/src/pages/Furniture.js
+++ b/src/pages/Furniture.js
@@ -1,11 +1,8 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
import ProductCard from '../components/ProductCard';
-class Furniture extends Component {
- constructor(props) {
- super(props);
- this.state = {
- furnitureProducts: [
+const Furniture = ({ onAddToCart }) => {
+ const [furnitureProducts] = useState([
{
id: 1,
name: "Victorian Mahogany Writing Desk",
@@ -86,11 +83,7 @@ class Furniture extends Component {
category: "furniture"
}
]
- };
- }
-
- render() {
- const { onAddToCart } = this.props;
+ );
return (
@@ -134,7 +127,7 @@ class Furniture extends Component {
Available Furniture
- {this.state.furnitureProducts.map(product => (
+ {furnitureProducts.map(product => (
);
- }
-}
+};
export default Furniture;
diff --git a/src/pages/Home.js b/src/pages/Home.js
index a72dfa4..1957cd7 100644
--- a/src/pages/Home.js
+++ b/src/pages/Home.js
@@ -1,11 +1,8 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
import ProductCard from '../components/ProductCard';
-class Home extends Component {
- constructor(props) {
- super(props);
- this.state = {
- featuredProducts: [
+const Home = ({ onAddToCart, onNavigate }) => {
+ const [featuredProducts] = useState([
{
id: 1,
name: "Victorian Mahogany Writing Desk",
@@ -47,11 +44,7 @@ class Home extends Component {
category: "furniture"
}
]
- };
- }
-
- render() {
- const { onAddToCart } = this.props;
+ );
return (
@@ -64,7 +57,7 @@ class Home extends Component {
features authentic antiques from around the globe, each piece telling its own
unique story of craftsmanship and heritage.
- this.props.onNavigate('products')}>
+ onNavigate('products')}>
Explore Collection
@@ -106,7 +99,7 @@ class Home extends Component {
Featured Treasures
Handpicked exceptional pieces from our collection
- {this.state.featuredProducts.map(product => (
+ {featuredProducts.map(product => (
this.props.onNavigate('products')}
+ onClick={() => onNavigate('products')}
>
View All Products
@@ -153,7 +146,6 @@ class Home extends Component {
);
- }
-}
+};
export default Home;
diff --git a/src/pages/Jewelry.js b/src/pages/Jewelry.js
index aa76030..6aee57b 100644
--- a/src/pages/Jewelry.js
+++ b/src/pages/Jewelry.js
@@ -1,11 +1,8 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
import ProductCard from '../components/ProductCard';
-class Jewelry extends Component {
- constructor(props) {
- super(props);
- this.state = {
- jewelryProducts: [
+const Jewelry = ({ onAddToCart }) => {
+ const [jewelryProducts] = useState([
{
id: 2,
name: "Art Deco Pearl Necklace",
@@ -85,11 +82,7 @@ class Jewelry extends Component {
category: "jewelry"
}
]
- };
- }
-
- render() {
- const { onAddToCart } = this.props;
+ );
return (
@@ -133,7 +126,7 @@ class Jewelry extends Component {
Available Jewelry
- {this.state.jewelryProducts.map(product => (
+ {jewelryProducts.map(product => (
);
- }
-}
+};
export default Jewelry;