-
Notifications
You must be signed in to change notification settings - Fork 4
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
10 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,61 @@ | ||
<template> | ||
<div | ||
v-show="cartIsOpen" | ||
class="fixed h-full border-gray border-r w-full bg-white z-10 max-w-sm overflow-y-auto right-0" | ||
> | ||
<div | ||
class="bg-gray-light border-b border-gray flex items-center justify-between h-12" | ||
> | ||
<div class="pl-5 ml-0 mr-auto uppercase">Cart</div> | ||
<button class="w-12 h-12 p-3 mr-0" @click="toggleCart"> | ||
<BaseIcon svg="multiply.svg" /> | ||
</button> | ||
</div> | ||
<client-only> | ||
<div v-if="CartId"> | ||
<apollo-query | ||
:query="require('~/queries/getCartDetails.graphql')" | ||
:variables="{ cartId: CartId }" | ||
> | ||
<template | ||
slot-scope="{ result: { loading, error, data }, isLoading }" | ||
> | ||
<!-- Loading --> | ||
<BaseLoader v-if="isLoading" /> | ||
<!-- Error --> | ||
<div v-else-if="error" class="error apollo">An error occurred</div> | ||
<!-- Result --> | ||
<div v-else-if="data"> | ||
<div v-for="item in data.cart.items" :key="item.product.id"> | ||
<img | ||
:src="item.product.small_image.url" | ||
:alt="item.product.small_image.label" | ||
width="100" | ||
/> | ||
{{ item.product.name }} | ||
</div> | ||
</div> | ||
</template> | ||
</apollo-query> | ||
</div> | ||
</client-only> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
apollo: { | ||
CartId: require('~/queries/getCartId.graphql') | ||
}, | ||
computed: { | ||
cartIsOpen() { | ||
return this.$store.state.cartIsOpen | ||
} | ||
}, | ||
methods: { | ||
toggleCart() { | ||
this.$store.commit('toggleCart') | ||
} | ||
} | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ query getCartDetails($cartId: String!) { | |
id | ||
items { | ||
id | ||
prices { | ||
price { | ||
value | ||
} | ||
} | ||
product { | ||
id | ||
name | ||
|
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,3 @@ | ||
query CartId { | ||
CartId @client | ||
} |
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,3 @@ | ||
mutation setCartId($value: String!) { | ||
setCartId(value: $value) @client | ||
} |
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,9 +1,13 @@ | ||
export const state = () => ({ | ||
navigationIsOpen: false | ||
navigationIsOpen: false, | ||
cartIsOpen: false | ||
}) | ||
|
||
export const mutations = { | ||
toggleNavigation(state) { | ||
state.navigationIsOpen = !state.navigationIsOpen | ||
}, | ||
toggleCart(state) { | ||
state.cartIsOpen = !state.cartIsOpen | ||
} | ||
} |