diff --git a/src/App.js b/src/App.js index ab1668b..ee00e13 100644 --- a/src/App.js +++ b/src/App.js @@ -9,31 +9,7 @@ import HomePage from './pages/home'; import './App.scss'; function App() { - return ( - -
- -
- - - - - - - - - - - - - - - - - -
- - ); + return 'Hello App'; } export default App; diff --git a/src/cart-context.js b/src/cart-context.js index a58b8b5..1464112 100644 --- a/src/cart-context.js +++ b/src/cart-context.js @@ -7,61 +7,8 @@ const CartDispatchContext = React.createContext(); function cartReducer(state, action) { switch (action.type) { - case 'increment': { - const product = action.payload; - const currentEntry = state.products[product.id]; - let newEntry; - if (currentEntry) { - newEntry = { - ...currentEntry, - quantity: currentEntry.quantity + 1, - }; - } else { - newEntry = { - ...product, - quantity: 1, - }; - } - - const { finalPrice } = calculatePriceDetails(product.price); - return { - ...state, - totalQuantity: state.totalQuantity + 1, - totalPrice: state.totalPrice + finalPrice, - products: { - ...state.products, - [product.id]: newEntry, - }, - }; - } - case 'decrement': { - const product = action.payload; - const currentEntry = state.products[product.id]; - if (!currentEntry) return state; - - let newEntry; - if (currentEntry.quantity === 1) { - newEntry = null; - } else { - newEntry = { - ...currentEntry, - quantity: currentEntry.quantity - 1, - }; - } - - const { finalPrice } = calculatePriceDetails(product.price); - return { - ...state, - totalQuantity: state.totalQuantity - 1, - totalPrice: state.totalPrice - finalPrice, - products: { - ...state.products, - [product.id]: newEntry, - }, - }; - } default: { - throw new Error(`Unhandled action type: ${action.type}`); + return state; } } } diff --git a/src/components/general/CurrencyFormat.js b/src/components/general/CurrencyFormat.js index 017ed0d..de7d12a 100644 --- a/src/components/general/CurrencyFormat.js +++ b/src/components/general/CurrencyFormat.js @@ -13,24 +13,8 @@ const currencyCodeLocaleMap = { INR: 'en-IN', }; -function CurrencyFormat({ - className, - value, - currencyCode, - iconSize = 1, - ...remainingProps -}) { - return ( -
- - - {value.toLocaleString(currencyCodeLocaleMap[currencyCode])} - -
- ); +function CurrencyFormat({}) { + return null; } export default CurrencyFormat; diff --git a/src/components/header/Account.js b/src/components/header/Account.js index d656fee..20b2bb6 100644 --- a/src/components/header/Account.js +++ b/src/components/header/Account.js @@ -5,15 +5,7 @@ import { mdiMenuDown } from '@mdi/js'; import './Account.scss'; function Account() { - return ( -
-
Hello, Sign in
-
- My Account - -
-
- ); + return null; } export default Account; diff --git a/src/components/header/Cart.js b/src/components/header/Cart.js index 87bd351..80d050c 100644 --- a/src/components/header/Cart.js +++ b/src/components/header/Cart.js @@ -8,14 +8,7 @@ import './Cart.scss'; import { useCartState } from 'cart-context'; function Cart() { - const { totalQuantity } = useCartState(); - - return ( - - -
{totalQuantity}
- - ); + return null; } export default Cart; diff --git a/src/components/header/DeliveryLocation.js b/src/components/header/DeliveryLocation.js index 8710830..7af1e24 100644 --- a/src/components/header/DeliveryLocation.js +++ b/src/components/header/DeliveryLocation.js @@ -5,19 +5,7 @@ import { mdiMapMarkerOutline } from '@mdi/js'; import './DeliveryLocation.scss'; function DeliveryLocation() { - return ( -
- -
-
Hello
-
Select your address
-
-
- ); + return null; } export default DeliveryLocation; diff --git a/src/components/header/Logo.js b/src/components/header/Logo.js index 1058593..ffe24bc 100644 --- a/src/components/header/Logo.js +++ b/src/components/header/Logo.js @@ -6,12 +6,7 @@ import { Link } from 'react-router-dom'; import './Logo.scss'; function Logo({ country = 'in' }) { - return ( - - Amazon - {country && .{country}} - - ); + return null; } export default Logo; diff --git a/src/components/header/Orders.js b/src/components/header/Orders.js index 5dd1e6a..71852de 100644 --- a/src/components/header/Orders.js +++ b/src/components/header/Orders.js @@ -3,12 +3,7 @@ import React from 'react'; import './Orders.scss'; function Orders() { - return ( -
-
Returns
-
& Orders
-
- ); + return null; } export default Orders; diff --git a/src/components/header/Search.js b/src/components/header/Search.js index 0ecad38..86bc68d 100644 --- a/src/components/header/Search.js +++ b/src/components/header/Search.js @@ -52,25 +52,7 @@ const categories = [ function Search() { const [category, setCategory] = useState(0); - return ( -
- - - -
- ); + return null; } export default Search; diff --git a/src/components/product/AddToCart.js b/src/components/product/AddToCart.js index 1158c18..562a8fd 100644 --- a/src/components/product/AddToCart.js +++ b/src/components/product/AddToCart.js @@ -7,39 +7,7 @@ import './AddToCart.scss'; import { useCartDispatch, useCartState } from 'cart-context'; function AddToCard({ product }) { - const { products } = useCartState(); - const dispatch = useCartDispatch(); - - const cartEntry = products[product.id]; - - if (cartEntry) { - return ( -
- -
{cartEntry.quantity}
- -
- ); - } else { - return ( - - ); - } + return null; } export default AddToCard; diff --git a/src/components/product/ImageSlider.js b/src/components/product/ImageSlider.js index 77e2dd6..5143e62 100644 --- a/src/components/product/ImageSlider.js +++ b/src/components/product/ImageSlider.js @@ -20,31 +20,7 @@ function ImageSlider({ product }) { const imageClick = (src) => { setImage(src); }; - return ( -
-
-
    - {images && - images.map((image, i) => ( -
  • { - imageClick(image); - }} - > - {product.title} -
  • - ))} -
-
-
-
- {product.title} -
-
-
- ); + return null; } export default ImageSlider; diff --git a/src/components/product/Information.js b/src/components/product/Information.js index 8c7a3c6..77abcc6 100644 --- a/src/components/product/Information.js +++ b/src/components/product/Information.js @@ -6,74 +6,7 @@ import CurrencyFormat from 'components/general/CurrencyFormat'; import AddToCard from 'components/product/AddToCart'; function Information({ product }) { - const { finalPrice, basePrice } = calculatePriceDetails( - product.price, - ); - return ( - <> - {product && ( -
-
{product.title}
-
Brand: {product.category}
- {product.rating && ( -
- -
{product.rating.count} ratings
-
- )} - - {product.price && ( -
-
- M.R.P. : - -
-
- Price. : - -
-
- You Save : - {product.price.discount} -
-
- )} - - - - -
- {product.specs && - product.specs.map((spec, i) => ( -
- {spec.name} : {spec.value} -
- ))} -
- -
-
About this item
-
    - {product.features && - product.features.map((feature, i) => ( -
  • - {feature} -
  • - ))} -
-
-
- )} - - ); + return null; } export default Information; diff --git a/src/pages/cart/CartItem.js b/src/pages/cart/CartItem.js index af14ff5..d918103 100644 --- a/src/pages/cart/CartItem.js +++ b/src/pages/cart/CartItem.js @@ -9,41 +9,7 @@ import { calculatePriceDetails } from 'utils.js/product'; import AddToCard from 'components/product/AddToCart'; function CartItem({ product }) { - const { finalPrice } = calculatePriceDetails(product.price); - return ( -
-
- {product.title} -
-
-
{product.title}
-
by {product.brand}
-
-
-
- -
-
- -
-
- -
-
=
-
- -
-
-
- ); + return null; } export default CartItem; diff --git a/src/pages/cart/index.js b/src/pages/cart/index.js index daeaa01..92c1b7f 100644 --- a/src/pages/cart/index.js +++ b/src/pages/cart/index.js @@ -7,29 +7,7 @@ import CartItem from './CartItem'; import CurrencyFormat from 'components/general/CurrencyFormat'; function CartPage() { - const { products, totalQuantity, totalPrice } = useCartState(); - const productIds = Object.keys(products).filter((id) => products[id]); - - return ( -
-
-
- {productIds.map((id) => ( - - ))} -
- -
- Subtotal ({totalQuantity} items):{' '} - -
-
-
- ); + return null; } export default CartPage; diff --git a/src/pages/home/Banner.js b/src/pages/home/Banner.js index 61f105b..84ad5fd 100644 --- a/src/pages/home/Banner.js +++ b/src/pages/home/Banner.js @@ -12,38 +12,7 @@ const banners = [ ]; function Banner() { - return ( -
-
- ( - - )} - renderCenterRightControls={({ nextSlide }) => ( - - )} - renderBottomCenterControls={() => null} - > - {banners.map((bannerSrc, index) => ( - {`Banner - ))} - -
-
- ); + return null } export default Banner; diff --git a/src/pages/home/ProductCard.js b/src/pages/home/ProductCard.js index ccccd81..4df9fee 100644 --- a/src/pages/home/ProductCard.js +++ b/src/pages/home/ProductCard.js @@ -10,50 +10,7 @@ import AddToCard from 'components/product/AddToCart'; import { calculatePriceDetails } from 'utils.js/product'; function ProductCard({ className, product }) { - const { finalPrice, basePrice, isDiscounted } = calculatePriceDetails( - product.price, - ); - - return ( -
-
-
{product.title}
-
- - {isDiscounted && ( - - )} -
- -
- -
- {product.rating.count} ratings -
-
- - - {product.title} - - -
- -
-
-
- ); + return null; } export default ProductCard; diff --git a/src/pages/home/Products.js b/src/pages/home/Products.js index 721fd92..d322833 100644 --- a/src/pages/home/Products.js +++ b/src/pages/home/Products.js @@ -9,41 +9,18 @@ import ProductCard from './ProductCard'; function Products() { const [products, setProducts] = useState([]); - const [loading, setLoading] = useState(false); - const [error, setError] = useState(null); const loadProducts = useCallback(async () => { - if (loading || products.length > 0) return; - - setLoading(true); - setError(null); - - try { - const json = await productsApi.getList(); - setProducts(json); - } catch (_error) { - setError(_error); - } - setLoading(false); - }, [loading, products]); + const json = await productsApi.getList(); + setProducts(json); + console.log(json); + }) useEffect(() => { loadProducts(); }, [loadProducts]); - if (loading) { - return ; - } else if (error) { - return ; - } else { - return ( -
- {products.map((product) => ( - - ))} -
- ); - } + return null; } export default Products; diff --git a/src/pages/home/index.js b/src/pages/home/index.js index bdc9df6..cf66a28 100644 --- a/src/pages/home/index.js +++ b/src/pages/home/index.js @@ -7,11 +7,8 @@ import Products from './Products'; function HomePage() { return ( -
- -
- -
+
+
); } diff --git a/src/pages/product/index.js b/src/pages/product/index.js index 6f05ffa..44cef53 100644 --- a/src/pages/product/index.js +++ b/src/pages/product/index.js @@ -10,47 +10,7 @@ import Error from 'components/general/Error'; import products from 'api/products'; function ProductPage() { - let { productId } = useParams(); - - const [product, setProduct] = useState(null); - const [loading, setLoading] = useState(false); - const [error, setError] = useState(null); - - const loadProduct = useCallback(async () => { - if (loading || product) return; - - setLoading(true); - setError(null); - - try { - const json = await productsApi.getProduct(productId); - console.log(json) - setProduct(json); - } catch (_error) { - setError(_error); - } - setLoading(false); - }, [loading]); - - useEffect(() => { - loadProduct(); - }, [loadProduct]); - - - if (loading) { - return ; - } else if (error) { - return ; - } else if (product) { - return ( -
- - -
- ); - } else { - return null; - } + return null; } export default ProductPage;