Skip to content
Merged
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
236 changes: 236 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,227 @@
flex: 1;
}

.products-page,
.product-details {
max-width: 1100px;
margin: 0 auto;
padding: 4rem 1.5rem;
}

.products-hero {
max-width: 620px;
margin-bottom: 3rem;
}

.eyebrow,
.product-category {
color: #726fc1;
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}

.products-hero h1 {
margin: 0.5rem 0 1rem;
color: #213547;
font-size: clamp(2.25rem, 5vw, 4rem);
letter-spacing: -0.05em;
line-height: 1;
}

.products-hero > p:last-child {
color: #666;
font-size: 1.1rem;
}

.product-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 1.25rem;
}

.product-card {
display: flex;
flex-direction: column;
overflow: hidden;
border: 1px solid #e7e7ed;
border-radius: 14px;
color: inherit;
text-decoration: none;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
box-shadow: 0 12px 30px rgba(33, 53, 71, 0.12);
transform: translateY(-4px);
}

.product-card-image {
display: grid;
height: 220px;
place-items: center;
padding: 1.5rem;
background: #fafafe;
}

.product-card-image img {
width: 100%;
height: 100%;
object-fit: contain;
}

.product-card-content {
display: flex;
flex: 1;
flex-direction: column;
padding: 1.25rem;
}

.product-card .product-category {
margin: 0 0 0.6rem;
font-size: 0.65rem;
}

.product-card h2 {
margin: 0;
color: #213547;
font-size: 1rem;
line-height: 1.35;
}

.product-price,
.product-details-price {
color: #213547;
font-size: 1.25rem;
font-weight: 700;
}

.view-product {
margin-top: auto;
padding-top: 1.25rem;
color: #726fc1;
font-size: 0.9rem;
font-weight: 700;
}

.products-message {
padding: 2rem;
border: 1px solid #f0caca;
border-radius: 10px;
color: #a33;
text-align: center;
}

.back-link {
display: inline-block;
margin-bottom: 2rem;
color: #726fc1;
font-weight: 700;
text-decoration: none;
}

.product-details-card {
display: grid;
grid-template-columns: minmax(280px, 0.9fr) minmax(300px, 1.1fr);
gap: clamp(2rem, 6vw, 6rem);
align-items: center;
}

.product-details-image {
display: grid;
min-height: 430px;
place-items: center;
padding: 3rem;
border-radius: 18px;
background: #fafafe;
}

.product-details-image img {
width: 100%;
max-height: 390px;
object-fit: contain;
}

.product-details-content h1 {
margin: 0.5rem 0 1rem;
color: #213547;
font-size: clamp(2rem, 4vw, 3.25rem);
letter-spacing: -0.04em;
line-height: 1.05;
}

.product-details-price {
margin: 0 0 1.5rem;
font-size: 1.75rem;
}

.product-description {
color: #5e6268;
line-height: 1.7;
}

.product-rating {
display: flex;
gap: 1rem;
margin: 1.5rem 0;
color: #666;
font-size: 0.9rem;
}

.product-rating span:first-child {
color: #b47b00;
font-weight: 700;
}

.add-to-cart-button {
width: 100%;
padding: 0.95rem 1.25rem;
border: 0;
border-radius: 8px;
background: #726fc1;
color: #fff;
cursor: pointer;
font: inherit;
font-weight: 700;
transition: background 0.2s ease;
}

.add-to-cart-button:hover {
background: #5e5ba8;
}

.product-details-error {
text-align: center;
}

.product-details-error h1 {
color: #213547;
}

html[data-theme="dark"] .products-hero h1,
html[data-theme="dark"] .product-card h2,
html[data-theme="dark"] .product-details-content h1,
html[data-theme="dark"] .product-details-error h1,
html[data-theme="dark"] .product-price,
html[data-theme="dark"] .product-details-price {
color: #dbe8f2;
}

html[data-theme="dark"] .products-hero > p:last-child,
html[data-theme="dark"] .product-description {
color: #b9c4ce;
}

html[data-theme="dark"] .product-card {
border-color: #2b3340;
}

html[data-theme="dark"] .product-card-image,
html[data-theme="dark"] .product-details-image {
background: #10151c;
}

.welcome h1 {
font-size: 2rem;
margin-bottom: 1rem;
Expand Down Expand Up @@ -341,6 +562,21 @@ html[data-theme="dark"] .mobile-link {
padding: 2rem 1rem;
}

.products-page,
.product-details {
padding: 2.5rem 1rem;
}

.product-details-card {
grid-template-columns: 1fr;
gap: 2rem;
}

.product-details-image {
min-height: 300px;
padding: 2rem;
}

.welcome h1 {
font-size: 1.6rem;
}
Expand Down
8 changes: 4 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Welcome from "./components/Welcome.jsx";
import "./App.css";
import { Route, Routes } from "react-router-dom";
import ErrorPage from "./components/ErrorPage.jsx";
import Footer from "./components/Footer.jsx";
import Navbar from "./components/Navbar.jsx";
import ProductDetails from "./components/ProductDetails.jsx";
import ProductList from "./components/ProductList.jsx";

function App() {
return (
Expand All @@ -14,13 +15,12 @@ function App() {
path="/"
element={
<>
<div className="app">
<Welcome />
</div>
<ProductList />
<Footer />
</>
}
/>
<Route path="/products/:productId" element={<ProductDetails />} />

<Route path="*" element={<ErrorPage />} />
</Routes>
Expand Down
73 changes: 73 additions & 0 deletions src/components/ProductDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { useEffect, useState } from "react";
import { Link, useParams } from "react-router-dom";
import Loading from "./Loading.jsx";

function ProductDetails() {
const { productId } = useParams();
const [product, setProduct] = useState(null);
const [status, setStatus] = useState("loading");
const [addedToCart, setAddedToCart] = useState(false);

useEffect(() => {
const loadProduct = async () => {
try {
const response = await fetch(
`https://fakestoreapi.com/products/${productId}`,
);
if (!response.ok) {
throw new Error("Product not found");
}
setProduct(await response.json());
setStatus("success");
} catch {
setStatus("error");
}
};

loadProduct();
}, [productId]);

if (status === "loading") {
return <Loading />;
}

if (status === "error" || !product) {
return (
<main className="product-details product-details-error">
<h1>Product not found</h1>
<p>We couldn&apos;t find the product you requested.</p>
<Link className="back-link" to="/">← Back to products</Link>
</main>
);
}

return (
<main className="product-details">
<Link className="back-link" to="/">← Back to products</Link>
<section className="product-details-card">
<div className="product-details-image">
<img src={product.image} alt={product.title} />
</div>
<div className="product-details-content">
<p className="product-category">{product.category}</p>
<h1>{product.title}</h1>
<p className="product-details-price">${product.price.toFixed(2)}</p>
<p className="product-description">{product.description}</p>
<div className="product-rating">
<span aria-label={`${product.rating.rate} out of 5 stars`}>★ {product.rating.rate}</span>
<span>{product.rating.count} reviews</span>
</div>
<button
className="add-to-cart-button"
type="button"
onClick={() => setAddedToCart(true)}
>
{addedToCart ? "Added to cart ✓" : "Add to Cart"}
</button>
</div>
</section>
</main>
);
}

export default ProductDetails;
Loading