feat: Initial Catalog
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import './App.css'
|
||||
|
||||
import { Catalog } from './pages'
|
||||
function App() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Catalog/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
47
src/pages/catalog/catalog.tsx
Normal file
47
src/pages/catalog/catalog.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Card } from "./components";
|
||||
|
||||
type Product = {
|
||||
id: number;
|
||||
name : string;
|
||||
price: number;
|
||||
description: string;
|
||||
image: string;
|
||||
};
|
||||
|
||||
const Catalog = () => {
|
||||
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchProducts(){
|
||||
try{
|
||||
const response = await fetch("http://localhost:8010/api/v1/products");
|
||||
const data = await response.json();
|
||||
setProducts(data);
|
||||
}catch(error){
|
||||
console.error(`Este es el error: ${error}`);
|
||||
};
|
||||
};
|
||||
fetchProducts();
|
||||
}, []);
|
||||
|
||||
console.log(products);
|
||||
return (
|
||||
<>
|
||||
{ products.map((product) => {
|
||||
return (
|
||||
<Card
|
||||
image={product.image}
|
||||
name={product.name}
|
||||
price={product.price}
|
||||
description={ product.description}
|
||||
cardId={product.id}
|
||||
/>
|
||||
)
|
||||
}) }
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Catalog;
|
||||
31
src/pages/catalog/components/card/card.tsx
Normal file
31
src/pages/catalog/components/card/card.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
type CardProps = {
|
||||
image: string;
|
||||
name: string;
|
||||
price: number;
|
||||
description: string;
|
||||
cardId: number
|
||||
}
|
||||
|
||||
|
||||
const Card = ({ image, name, price, description, cardId } : CardProps) => {
|
||||
return (
|
||||
<div key={cardId}>
|
||||
<div>
|
||||
<img src={`${image}`} alt="Imagen"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p>{name}</p>
|
||||
<p>{price}</p>
|
||||
<p>{description}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button>Conocer Origen</button>
|
||||
<button>Agregar</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Card;
|
||||
1
src/pages/catalog/components/card/index.ts
Normal file
1
src/pages/catalog/components/card/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as Card } from './card.tsx';
|
||||
2
src/pages/catalog/components/index.ts
Normal file
2
src/pages/catalog/components/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './card/';
|
||||
export * from './index';
|
||||
1
src/pages/catalog/index.ts
Normal file
1
src/pages/catalog/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as Catalog} from './catalog.tsx';
|
||||
1
src/pages/index.ts
Normal file
1
src/pages/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './catalog/';
|
||||
Reference in New Issue
Block a user