Skip to content
Open

done #52

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
11,970 changes: 31 additions & 11,939 deletions package-lock.json

Large diffs are not rendered by default.

51 changes: 26 additions & 25 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
.App {
text-align: center;
box-sizing: border-box;
}

.App-logo {
height: 40vmin;
pointer-events: none;
.search-bar {
display: flex;
flex-direction: column;
align-items: center;
font-size: 1rem;
margin-bottom: 50px
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
.search-bar p {
margin: 0;
font-size: 1.3rem
}

.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;
#search {
width: 800px;
padding: 10px;
font-size: 1rem
}

.App-link {
color: #61dafb;
.checkBox-container {
margin-top: 10px
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
.product-table {
/* display: flex;
align-items: center;
flex-direction: column; */
margin: auto;
width: 800px
}

thead {
background-color: gray;
}
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 './App.css';
import ProductsPage from './Components/ProductsPage';

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>
<ProductsPage />
</div>
);
}
Expand Down
26 changes: 26 additions & 0 deletions src/Components/ProductTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";

function ProductTable(props) {

return (
<table className="product-table">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{props.products.map((product) => {
return (
<tr key={product.id}>
<td>{product.name}</td>
<td>{product.price}</td>
</tr>
)
})}
</tbody>
</table>
)
}
export default ProductTable;
36 changes: 36 additions & 0 deletions src/Components/ProductsPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

import { useState } from 'react';
import jsonData from '../data.json';
import SearchBar from './SearchBar';
import ProductTable from './ProductTable';

function ProductsPage() {

const [searchQuery, setSearchQuery] = useState('');
const [onlyInStock, setOnlyInStock] = useState(false);

const handleSearchChange = (query) => {
setSearchQuery(query);
};

const handleInStockChange = (event) => {
setOnlyInStock(event.target.checked);
};

const filteredProducts = jsonData.filter((product) => {
const matchesSearchQuery = product.name.toLowerCase().includes(searchQuery.toLowerCase());
const matchesStockFilter = !onlyInStock || product.inStock;
return matchesSearchQuery && matchesStockFilter;
});


return (
<div>
<h1>Root Store</h1>
<SearchBar searchQuery={searchQuery} onSearchChange={handleSearchChange} checked={onlyInStock} onCheckChange={handleInStockChange} />
<ProductTable products={filteredProducts} />
</div>
)

};
export default ProductsPage;
17 changes: 17 additions & 0 deletions src/Components/SearchBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";

function SearchBar(props) {

return (
<div className="search-bar">
<p>Search</p>
<input type="text" placeholder="search for products" id="search" value={props.searchQuery} onChange={(e) => props.onSearchChange(e.target.value)} />
<div className="checkBox-container">
<input type="checkbox" id="check-box" checked={props.checked} onChange={props.onCheckChange} />
<span>Only show products available</span>
</div>
</div>
)
}

export default SearchBar;