This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fernando Fernández <ferferga@hotmail.com>
- Loading branch information
Showing
12 changed files
with
109 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
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,10 +1,18 @@ | ||
import { Product } from '@/api'; | ||
import { Ref, ref } from 'vue'; | ||
import { useStorage } from '@vueuse/core'; | ||
|
||
export const cart = useStorage( | ||
'cart', | ||
{ | ||
cart: [] as Product[], | ||
quantityMap: new Map<number, number>() | ||
}, | ||
localStorage | ||
); | ||
|
||
export const cart = ref<Product[]>([]); | ||
/** | ||
* | ||
* Retuns cart store | ||
*/ | ||
export function useCart(): Ref<Product[]> { | ||
export function useCart(): typeof cart { | ||
return cart; | ||
} |
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,36 @@ | ||
<template> | ||
<h3 style="text-align: center"> | ||
CARRITO | ||
</h3> | ||
<QList> | ||
<QItem | ||
v-for="item in cart.cart" | ||
:key="item.id"> | ||
<QItemSection> | ||
<QImg | ||
v-if="getActivityFromProduct(item.id)?.image.data" | ||
:src="getActivityFromProduct(item.id)?.image.data" /> | ||
<QItemLabel v-if="getActivityFromProduct(item.id)?.name">{{ getActivityFromProduct(item.id)?.name }}</QItemLabel> | ||
</QItemSection> | ||
<QItemSection side> | ||
<QItemLabel>{{ item.price }}€</QItemLabel> | ||
</QItemSection> | ||
</QItem> | ||
</QList> | ||
</template> | ||
<script setup lang="ts"> | ||
import { Activity } from '@/api'; | ||
import { activities } from '@/composables/use-activities'; | ||
import { useCart } from '@/composables/use-cart'; | ||
const cart = useCart(); | ||
function getActivityFromProduct(id: number | undefined): Activity | undefined { | ||
return activities.value.find(i => i.id === id); | ||
} | ||
function updateQuantity(productId: number, quantity: number) { | ||
cart.value.quantityMap.set(productId, quantity); | ||
} | ||
</script> |
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
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
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
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
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
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