diff --git a/package.json b/package.json
index f6f7903..111edb3 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
+ "lab-thinking-in-react-new": "file:",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
diff --git a/src/App.js b/src/App.js
index 3784575..e7a263c 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,23 +1,11 @@
-import logo from './logo.svg';
-import './App.css';
+
+import "./App.css";
+import ProductsPage from "./components/ProductsPage";
function App() {
return (
);
}
diff --git a/src/App.test.js b/src/App.test.js
deleted file mode 100644
index 1f03afe..0000000
--- a/src/App.test.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import { render, screen } from '@testing-library/react';
-import App from './App';
-
-test('renders learn react link', () => {
- render();
- const linkElement = screen.getByText(/learn react/i);
- expect(linkElement).toBeInTheDocument();
-});
diff --git a/src/components/ProductRow.js b/src/components/ProductRow.js
new file mode 100644
index 0000000..5657485
--- /dev/null
+++ b/src/components/ProductRow.js
@@ -0,0 +1,14 @@
+// src/components/ProductRow.js
+function ProductRow({ product }) {
+ const rowStyle = { color: product.inStock ? "black" : "red" };
+
+ 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..8f87e80
--- /dev/null
+++ b/src/components/ProductTable.js
@@ -0,0 +1,22 @@
+// src/components/ProductTable.js
+import ProductRow from "./ProductRow";
+
+function ProductTable({ products }) {
+ return (
+
+
+
+ | Name |
+ Price |
+
+
+
+ {products.map((product) => (
+
+ ))}
+
+
+ );
+}
+
+export default ProductTable;
diff --git a/src/components/ProductsPage.js b/src/components/ProductsPage.js
new file mode 100644
index 0000000..2db6436
--- /dev/null
+++ b/src/components/ProductsPage.js
@@ -0,0 +1,34 @@
+// src/components/ProductsPage.js
+import { useState } from "react";
+import jsonData from "../mydata.json";
+import SearchBar from "./SearchBar";
+import ProductTable from "./ProductTable";
+
+function ProductsPage() {
+ const [products] = useState(jsonData);
+ const [searchText, setSearchText] = useState("");
+ const [showInStockOnly, setShowInStockOnly] = useState(false);
+
+
+ const filteredProducts = products.filter((product) => {
+ const matchesSearch = product.name.toLowerCase().includes(searchText.toLowerCase());
+ const matchesStock = !showInStockOnly || product.inStock;
+ return matchesSearch && matchesStock;
+ });
+
+ return (
+
+ );
+}
+
+export default ProductsPage;
+
diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js
new file mode 100644
index 0000000..6e889a7
--- /dev/null
+++ b/src/components/SearchBar.js
@@ -0,0 +1,28 @@
+// src/components/SearchBar.js
+function SearchBar({ searchText, setSearchText, showInStockOnly, setShowInStockOnly }) {
+ const handleInputChange = (event) => setSearchText(event.target.value);
+ const handleCheckboxChange = (event) => setShowInStockOnly(event.target.checked);
+
+ return (
+
+
+
+
+ );
+}
+
+export default SearchBar;
+
diff --git a/src/index.js b/src/index.js
index d563c0f..7716fe4 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,7 +2,6 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
-import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
@@ -11,7 +10,3 @@ root.render(
);
-// If you want to start measuring performance in your app, pass a function
-// to log results (for example: reportWebVitals(console.log))
-// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
-reportWebVitals();
diff --git a/src/data.json b/src/mydata.json
similarity index 100%
rename from src/data.json
rename to src/mydata.json