From 1db0657ae0f8dbc77aa7380bdee48218ec9e8aa0 Mon Sep 17 00:00:00 2001
From: Navin-nash <1923014@saec.ac.in>
Date: Tue, 8 Oct 2024 21:19:34 +0530
Subject: [PATCH] Done
---
src/App.js | 16 ++-------------
src/components/ProductRow.js | 12 +++++++++++
src/components/ProductTable.js | 22 ++++++++++++++++++++
src/components/ProductsPage.js | 28 +++++++++++++++++++++++++
src/components/SearchBar.js | 37 ++++++++++++++++++++++++++++++++++
5 files changed, 101 insertions(+), 14 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..6e32c7d 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,23 +1,11 @@
import logo from './logo.svg';
import './App.css';
+import ProductsPage from './components/ProductsPage';
function App() {
return (
);
}
diff --git a/src/components/ProductRow.js b/src/components/ProductRow.js
new file mode 100644
index 0000000..4725a8c
--- /dev/null
+++ b/src/components/ProductRow.js
@@ -0,0 +1,12 @@
+function ProductRow({ product }) {
+ return (
+
+ | {product.name} |
+ {product.price} |
+ {product.inStock ? 'In Stock' : 'Out of Stock'} |
+
+ );
+ }
+
+ 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..71480ba
--- /dev/null
+++ b/src/components/ProductTable.js
@@ -0,0 +1,22 @@
+import ProductRow from './ProductRow';
+
+function ProductTable({ products }) {
+ return (
+
+
+
+ | Name |
+ Price |
+ Status |
+
+
+
+ {products.map((product) => (
+
+ ))}
+
+
+ );
+}
+
+export default ProductTable;
diff --git a/src/components/ProductsPage.js b/src/components/ProductsPage.js
new file mode 100644
index 0000000..96e1567
--- /dev/null
+++ b/src/components/ProductsPage.js
@@ -0,0 +1,28 @@
+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 [filteredProducts, setFilteredProducts] = useState(products);
+
+ const handleSearch = (searchTerm) => {
+ const filtered = products.filter(product =>
+ product.name.toLowerCase().includes(searchTerm.toLowerCase())
+ );
+ setFilteredProducts(filtered);
+ };
+
+ return (
+
+ );
+}
+
+export default ProductsPage;
diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js
new file mode 100644
index 0000000..dc5af9f
--- /dev/null
+++ b/src/components/SearchBar.js
@@ -0,0 +1,37 @@
+import { useState } from 'react';
+
+function SearchBar({ onSearch }) {
+ const [searchTerm, setSearchTerm] = useState('');
+ const [onlyInStock, setOnlyInStock] = useState(false);
+
+ const handleChange = (event) => {
+ setSearchTerm(event.target.value);
+ onSearch(event.target.value, onlyInStock); // Include stock filter
+ };
+
+ const handleCheckboxChange = (event) => {
+ setOnlyInStock(event.target.checked);
+ onSearch(searchTerm, event.target.checked); // Trigger search with stock filter
+ };
+
+ return (
+
+
+
+
+ );
+}
+
+export default SearchBar;