Skip to content
Open

done #46

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 15 additions & 33 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
margin: 0;
padding: 0;
}

.App-link {
color: #61dafb;
.App {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
h1 {
color: #343a40;
text-align: center;
}
17 changes: 2 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import logo from './logo.svg';
import ProductPage from './components/ProductPage';
import './App.css';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<ProductPage />
</div>
);
}
Expand Down
26 changes: 26 additions & 0 deletions src/components/ProductPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useState } from "react";
import ProductTable from "./ProductTable";
import SearchBar from "./SearchBar";
import jsonData from '../data.json';
import './ProductsPage.css'

export default function ProductPage() {
const [products] = useState(jsonData);
const [searchTerm, setSearchTerm] = useState('');
const [inStockOnly, setInStockOnly] = useState(false);

const handleSearch = (term) => {
setSearchTerm(term);
};

const handleInStockChange = (inStock) => {
setInStockOnly(inStock);
}
return (
<div className="ProductsPage">
<h1>Root Store</h1>
<SearchBar onSearch={handleSearch} onInStockChange={handleInStockChange}/>
<ProductTable products={products} searchTerm={searchTerm} inStockOnly={inStockOnly}/>
</div>
)
}
4 changes: 4 additions & 0 deletions src/components/ProductRow.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.ProductRow td {
padding: 10px;
}

9 changes: 9 additions & 0 deletions src/components/ProductRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import './ProductRow.css'
export default function ProductRow({ product }) {
return (
<tr className='ProductRow'>
<td>{product.name}</td>
<td>{product.price}</td>
</tr>
)
}
19 changes: 19 additions & 0 deletions src/components/ProductTable.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.ProductTable {
width: 100%;
border-collapse: collapse;
}

.ProductTable th, .ProductTable td {
padding: 10px;
border: 1px solid #dee2e6;
text-align: left;
}

.ProductTable th {
background-color: #f1f1f1;
}

.ProductTable tr:nth-child(even) {
background-color: #f8f9fa;
}

25 changes: 25 additions & 0 deletions src/components/ProductTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ProductRow from "./ProductRow";
import './ProductTable.css';

export default function ProductTable({ products, searchTerm, inStockOnly }) {
const filteredProducts = products.filter((product) => {
const matchesSearchTerm = product.name.toLowerCase().includes(searchTerm.toLowerCase());
const matchesInStock = inStockOnly ? product.inStock : true;
return matchesSearchTerm && matchesInStock;
})
return (
<table className="ProductTable">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{filteredProducts.map((product) => (
<ProductRow key={product.id} product={product} />
))}
</tbody>
</table>
)
}
5 changes: 5 additions & 0 deletions src/components/ProductsPage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.ProductsPage {
padding: 20px;
background-color: #fff;
}

22 changes: 22 additions & 0 deletions src/components/SearchBar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.SearchBar {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}

.SearchBar input[type="text"] {
width: 70%;
padding: 8px;
border: 1px solid #ced4da;
border-radius: 4px;
}

.SearchBar label {
display: flex;
align-items: center;
}

.SearchBar input[type="checkbox"] {
margin-right: 5px;
}

19 changes: 19 additions & 0 deletions src/components/SearchBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import './SearchBar.css';
export default function SearchBar({ onSearch, onInStockChange }) {
const handleSearch = (event) => {
onSearch(event.target.value);
};

const handleInStockChange = (event) => {
onInStockChange(event.target.checked);
};
return (
<div className="SearchBar">
<input type="text" placeholder="Search..." onChange={handleSearch} />
<label>
<input type="checkbox" onChange={handleInStockChange} />
Only show products in stock
</label>
</div>
);
}