-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
15 deletions.
There are no files selected for viewing
27 changes: 15 additions & 12 deletions
27
pruebas/02-bazar-universal/dano2906/src/components/ProductCard.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
--- | ||
import { Image } from "astro:assets"; | ||
import productImage from "@assets/placeholder-product-image.png" | ||
import AddCartButton from "@components/AddCartButton.jsx"; | ||
import productImage from "../../public/placeholder-product-image.png" | ||
const {product} = Astro.props | ||
const {title,description,price,category,images,rating} = product | ||
const {id,title,description,price,category,rating} = product | ||
--- | ||
|
||
<article class="w-full h-auto p-3 flex flex-col items-center justify-center gap-y-1 bg-gradient-to-br from-blue-300 via-pink-300 to-orange-300 shadow-lg rounded-lg hover:opacity-75"> | ||
<article class="w-full h-auto p-3 flex flex-col items-start justify-start gap-y-1 bg-gradient-to-br from-blue-300 via-pink-300 to-orange-300 shadow-lg rounded-lg"> | ||
<div> | ||
<Image src={productImage} alt={title} width={192} height={192} class="rounded-lg"/> | ||
<Image src={productImage} alt={title} width={192} height={192} class="mx-auto rounded-lg" transition:name="img"/> | ||
</div> | ||
<div class="flex flex-col items-start justify-start"> | ||
<h2 class="text-2xl font-tilt font-bold text-purple-950">{title}</h2> | ||
<p class="text-lg font-tilt font-light text-purple-950">{description}</p> | ||
<span class="text-sm font-tilt font-normal text-purple-950">{category}</span> | ||
<span class="text-sm font-tilt font-light text-purple-950">Price: ${price}</span> | ||
<span class="text-sm font-tilt font-light text-purple-950">Rating: {rating}/5</span> | ||
</div> | ||
|
||
<a href=`/items/${id}` class="hover:opacity-75"> | ||
<div class="flex flex-col items-start justify-start"> | ||
<h2 class="text-2xl font-tilt font-bold text-purple-950" transition:name="title">{title}</h2> | ||
<p class="text-lg font-tilt font-light text-purple-950 [text-wrap:balance]" transition:name="desc">{description}</p> | ||
<span class="text-sm font-tilt font-normal text-purple-950" transition:name="category">{category}</span> | ||
<span class="text-sm font-tilt font-light text-purple-950" transition:name="price">Price: ${price}</span> | ||
<span class="text-sm font-tilt font-light text-purple-950" transition:name="rating">Rating: {rating}/5</span> | ||
</div> | ||
</a> | ||
<AddCartButton id={id} client:load/> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
pruebas/02-bazar-universal/dano2906/src/store/cartStore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { create } from 'zustand' | ||
import { persist } from 'zustand/middleware' | ||
|
||
export const useCartStore = create(persist( | ||
(set, get) => ({ | ||
cart: [], | ||
add: (id) => { | ||
if (!get().cart.some(instance => instance === id)) { | ||
set((state) => ({ | ||
cart: [...state.cart, id] | ||
})) | ||
} | ||
}, | ||
remove: (id) => ( | ||
set((state) => ({ | ||
cart: state.cart.filter(instance => instance !== id) | ||
})) | ||
), | ||
clean: () => ( | ||
set(() => ({ | ||
cart: [] | ||
})) | ||
) | ||
}), { | ||
name: 'cart' | ||
} | ||
)) |