From 3c6a5ee08f7c0abc6c55f4e3cd3f820fda87770e Mon Sep 17 00:00:00 2001 From: PalakJain1504 Date: Sun, 13 Oct 2024 19:46:30 +0530 Subject: [PATCH] done --- src/App.js | 18 +++--------------- src/components/ProductRow.js | 12 ++++++++++++ src/components/ProductTable.js | 22 ++++++++++++++++++++++ src/components/ProductsPage.js | 33 +++++++++++++++++++++++++++++++++ src/components/SearchBar.js | 23 +++++++++++++++++++++++ 5 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 src/components/ProductRow.js create mode 100644 src/components/ProductTable.js create mode 100644 src/components/ProductsPage.js create mode 100644 src/components/SearchBar.js diff --git a/src/App.js b/src/App.js index 3784575..5bd13b2 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,11 @@ -import logo from './logo.svg'; +// src/App.js import './App.css'; +import ProductsPage from './components/ProductsPage'; function App() { return (
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+
); } diff --git a/src/components/ProductRow.js b/src/components/ProductRow.js new file mode 100644 index 0000000..7c3eda6 --- /dev/null +++ b/src/components/ProductRow.js @@ -0,0 +1,12 @@ +// src/components/ProductRow.js +function ProductRow({ product }) { + return ( + + {product.name} + {product.price} + + ); + } + + export default ProductRow; + \ No newline at end of file diff --git a/src/components/ProductTable.js b/src/components/ProductTable.js new file mode 100644 index 0000000..b87be70 --- /dev/null +++ b/src/components/ProductTable.js @@ -0,0 +1,22 @@ +// src/components/ProductTable.js +import ProductRow from './ProductRow'; + +function ProductTable({ products }) { + return ( + + + + + + + + + {products.map(product => ( + + ))} + +
NamePrice
+ ); +} + +export default ProductTable; diff --git a/src/components/ProductsPage.js b/src/components/ProductsPage.js new file mode 100644 index 0000000..a0f6dcb --- /dev/null +++ b/src/components/ProductsPage.js @@ -0,0 +1,33 @@ +// src/components/ProductsPage.js +import { useState } from 'react'; +import jsonData from './../../data.json'; +import SearchBar from './SearchBar'; +import ProductTable from './ProductTable'; + +function ProductsPage() { + const [products, setProducts] = useState(jsonData); + const [searchTerm, setSearchTerm] = useState(""); + const [showInStock, setShowInStock] = useState(false); + + const filteredProducts = products + .filter(product => + product.name.toLowerCase().includes(searchTerm.toLowerCase()) + ) + .filter(product => + !showInStock || product.inStock + ); + + return ( +
+

Root Store

+ setShowInStock(!showInStock)} + /> + +
+ ); +} + +export default ProductsPage; diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js new file mode 100644 index 0000000..d17b9c0 --- /dev/null +++ b/src/components/SearchBar.js @@ -0,0 +1,23 @@ +// src/components/SearchBar.js +function SearchBar({ onSearch, showInStock, onToggleInStock }) { + return ( +
+ onSearch(e.target.value)} + /> + +
+ ); + } + + export default SearchBar; + \ No newline at end of file