Skip to content
Open
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
19 changes: 19 additions & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.product-card {
cursor: pointer;
}

.product-card:focus-visible {
outline: 2px solid #4ade80;
outline-offset: 4px;
}

.product-card.expanded {
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
}

.product-details {
margin-top: 0.75rem;
padding-top: 0.75rem;
border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.user-card h3, .product-card h3, .result-card h5 {
margin: 0 0 0.5rem 0;
color: #ffffff;
Expand Down
33 changes: 30 additions & 3 deletions client/src/components/products/Products.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function Products({ products, loading, fetchProducts, fetchAnalytics }) {
});
const [search, setSearch] = useState("");
const [categoryFilter, setCategoryFilter] = useState("");
const [expandedProductId, setExpandedProductId] = useState(null);

// Get unique categories from products
const categories = Array.from(new Set(products.map(p => p.category))).filter(Boolean);
Expand Down Expand Up @@ -44,6 +45,17 @@ function Products({ products, loading, fetchProducts, fetchAnalytics }) {
}
};

const toggleProductDetails = (productId) => {
setExpandedProductId((prevId) => (prevId === productId ? null : productId));
};

const handleCardKeyDown = (event, productId) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
toggleProductDetails(productId);
}
};

return (
<div className="tab-content">
<div className="form-section">
Expand Down Expand Up @@ -112,12 +124,27 @@ function Products({ products, loading, fetchProducts, fetchAnalytics }) {
<p>No products found.</p>
) : (
filteredProducts.map((product) => (
<div key={product.id} className="product-card">
<div
key={product.id}
className={`product-card ${expandedProductId === product.id ? 'expanded' : ''}`}
onClick={() => toggleProductDetails(product.id)}
onKeyDown={(event) => handleCardKeyDown(event, product.id)}
role="button"
tabIndex={0}
>
<h3>{product.name}</h3>
<p className="price">${product.price}</p>
<p className="category">{product.category}</p>
<p className={`stock ${product.stock < 20 ? 'low-stock' : ''}`}>Stock: {product.stock}</p>
<p className="description">{product.description}</p>
{expandedProductId === product.id && (
<div className="product-details">
<p className={`stock ${product.stock < 20 ? 'low-stock' : ''}`}>
Stock: {product.stock}
</p>
<p className="description">
{product.description ? product.description : 'No description available.'}
</p>
</div>
)}
</div>
))
)}
Expand Down