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
90 changes: 90 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,93 @@
.read-the-docs {
color: #888;
}

.App {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}

h1 {
text-align: center;
margin-bottom: 2rem;
color: #333;
}

.loading {
text-align: center;
font-size: 1.5rem;
color: #666;
margin-top: 2rem;
}

.products-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 2rem;
padding: 1rem;
}

.product-card {
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
padding: 1rem;
transition: transform 0.2s ease-in-out;
display: flex;
flex-direction: column;
}

.product-card:hover {
transform: translateY(-5px);
}

.product-card img {
width: 100%;
height: 200px;
object-fit: contain;
margin-bottom: 1rem;
background: #f5f5f5;
border-radius: 4px;
}

.product-card h3 {
font-size: 1rem;
margin: 0.5rem 0;
color: #333;
flex-grow: 1;
}

.price {
font-size: 1.25rem;
font-weight: bold;
color: #2c3e50;
margin: 0.5rem 0;
}

.category {
font-size: 0.9rem;
color: #666;
text-transform: capitalize;
margin: 0.5rem 0;
}

.rating {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.9rem;
color: #666;
margin-top: auto;
}

@media (max-width: 768px) {
.products-grid {
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1rem;
}

.App {
padding: 1rem;
}
}
83 changes: 55 additions & 28 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import { useEffect, useState } from "react";
import "./App.css";

interface Product {
id: number;
title: string;
price: number;
description: string;
category: string;
image: string;
rating: {
rate: number;
count: number;
};
}

function App() {
const [count, setCount] = useState(0)
const [products, setProducts] = useState<Product[]>([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetchProducts = async () => {
try {
const response = await fetch("https://fakestoreapi.com/products");
const data = await response.json();
setProducts(data);
} catch (error) {
console.error("Error fetching products:", error);
Copy link

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider displaying an error message to the user when product fetching fails instead of only logging the error to the console.

Suggested change
console.error("Error fetching products:", error);
console.error("Error fetching products:", error);
setError("Failed to fetch products. Please try again later.");

Copilot uses AI. Check for mistakes.
} finally {
setLoading(false);
}
};

fetchProducts();
}, []);

if (loading) {
return <div className="loading">Loading products...</div>;
}

return (
<>
<div>
<a href="https://vite.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
<div className="App">
<h1>Products</h1>
<div className="products-grid">
{products.map((product) => (
<div key={product.id} className="product-card">
<img src={product.image} alt={product.title} />
<h3>{product.title}</h3>
<p className="price">${product.price}</p>
<p className="category">{product.category}</p>
<div className="rating">
<span>⭐ {product.rating.rate}</span>
<span>({product.rating.count} reviews)</span>
</div>
</div>
))}
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
</div>
);
}

export default App
export default App;