-
Notifications
You must be signed in to change notification settings - Fork 39
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
5 changed files
with
58 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
// App-specific type definition go here | ||
export type CartItemOptions = { | ||
grantId: string; | ||
contributionTokenAddress: string; // store address instead of TokenInfo to reduce localStorage size used | ||
contributionAmount: string; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<template> | ||
<h1 class="my-6 text-center text-3xl font-extrabold text-gray-900">Cart</h1> | ||
|
||
<div v-if="cart.length === 0"> | ||
<div>Your cart is empty</div> | ||
<button @click="pushRoute({ name: 'dgrants' })" class="btn btn-primary mt-6">Browse Grants</button> | ||
</div> | ||
|
||
<div v-else> | ||
<div v-for="item in cart" :key="item.grantId" class="mb-10"> | ||
<div>{{ item }}</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent } from 'vue'; | ||
import { pushRoute, loadCart } from 'src/utils/utils'; | ||
import useDataStore from 'src/store/data'; | ||
import { CartItemOptions } from 'src/types'; | ||
import { Grant } from '@dgrants/types'; | ||
type CartItem = CartItemOptions & Grant; | ||
function useCart() { | ||
const { grants } = useDataStore(); | ||
const cart = computed(() => { | ||
// Load cart info form localStorage, then concatenate it with grant data from store | ||
const rawCart = loadCart(); | ||
return rawCart.map((cartItem) => { | ||
// grants.value is likely undefined as page first loads before data is fetched, hence the `grants.value &&` | ||
const grant = grants.value && grants.value.filter((grant) => grant.id.toString() === cartItem.grantId)[0]; // TODO `grants.value.filter` may be slow for large number of grants | ||
return { ...cartItem, ...grant } as CartItem; | ||
}); | ||
}); | ||
return { cart, grants }; | ||
} | ||
export default defineComponent({ | ||
name: 'Cart', | ||
setup() { | ||
return { ...useCart(), pushRoute }; | ||
}, | ||
}); | ||
</script> |