Skip to content

L10 end #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ body {
margin: 25px 100px;
float: right;
border: 1px solid #d8d8d8;
padding: 10px 30px;
padding: 30px 30px;
background-color: white;
-webkit-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
-moz-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
Expand Down Expand Up @@ -88,6 +88,10 @@ li {
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.57);
}

.out-of-stock-img {
opacity: 0.5;
}

p {
font-size: 22px;
}
Expand Down
137 changes: 66 additions & 71 deletions components/ProductDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,98 +5,93 @@ app.component('product-display', {
required: true
}
},
template:
/*html*/
`
<div class="product-display">

template:
/*html*/
`<div class="product-display">
<div class="product-container">
<div class="product-image">
<img :src="image" />
<img v-bind:src="image">
</div>

<div class="product-info">
<h1>{{ productName }}</h1>
<h1>{{ title }}</h1>

<p v-if="inStock">In Stock</p>
<p v-else>Out of Stock</p>
<p>Shipping: {{ shipping }}</p>

<p>Shipping: {{ shipping }}</p>
<ul>
<li v-for="detail in details">{{ detail }}</li>
</ul>

<div class="color-circle"
<div
v-for="(variant, index) in variants"
:key="variant.id"
:style="{ backgroundColor: variant.color }"
@mouseover="updateProduct(index)"
>
</div>

<button class="button" v-on:click="addToCart"
:disabled="!inStock"
:class="{ disabledButton: !inStock }"
>
Add to cart
:key="variant.id"
@mouseover="updateVariant(index)"
class="color-circle"
:style="{ backgroundColor: variant.color }">
</div>

<button
class="button"
:class="{ disabledButton: !inStock }"
:disabled="!inStock"
v-on:click="addToCart">
Add to Cart
</button>

<!-- solution -->
<button
class="button"
:class="{ disabledButton: !inStock }"
:disabled="!inStock"
@click="removeFromCart">
Remove Item
</button>
<!-- solution -->

</div>
</div>

<review-list :reviews="reviews"></review-list>
<review-form @review-submitted="addReview" ></review-form>
</div>
`,
</div>`,
data() {
return {
product: 'Socks',
brand: 'Vue Mastery',
selectedVariant: 0,
details: ['80% cotton', '20% polyester', 'Gender-neutral'],
variants: [
{
id: 2234,
color: 'green',
image: './assets/images/socks_green.jpg',
quantity: 10
},
{
id: 2235,
color: 'blue',
image: './assets/images/socks_blue.jpg',
quantity: 0
}
],
reviews: [],
tabs: ['review-form', 'review-list'],
activeTab: 'review-form'
product: 'Socks',
brand: 'Vue Mastery',
selectedVariant: 0,
details: ['50% cotton', '30% wool', '20% polyester'],
variants: [
{ id: 2234, color: 'green', image: './assets/images/socks_green.jpg', quantity: 50 },
{ id: 2235, color: 'blue', image: './assets/images/socks_blue.jpg', quantity: 0 },
]
}
},
methods: {
addToCart() {
this.$emit('add-to-cart', this.variants[this.selectedVariant].id)
},
updateProduct(index) {
this.selectedVariant = index
},
addReview(review) {
this.reviews.push(review)
}
addToCart() {
this.$emit('add-to-cart', this.variants[this.selectedVariant].id)
},
// solution
removeFromCart() {
this.$emit('remove-from-cart', this.variants[this.selectedVariant].id)
},
// solution
updateVariant(index) {
this.selectedVariant = index
}
},
computed: {
productName() {
return this.brand + ' ' + this.product
},
image() {
return this.variants[this.selectedVariant].image
},
inStock() {
return this.variants[this.selectedVariant].quantity
},
shipping() {
if (this.premium) {
return 'Free'
title() {
return this.brand + ' ' + this.product
},
image() {
return this.variants[this.selectedVariant].image
},
inStock() {
return this.variants[this.selectedVariant].quantity
},
shipping() {
if (this.premium) {
return 'Free'
}
return 2.99
}
return 2.99
}
}
})
})
52 changes: 0 additions & 52 deletions components/ReviewForm.js

This file was deleted.

22 changes: 0 additions & 22 deletions components/ReviewList.js

This file was deleted.

21 changes: 18 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@
<!-- Import Styles -->
<link rel="stylesheet" href="./assets/styles.css" />
<!-- Import Vue.js -->
<script src="https://unpkg.com/[email protected].0-beta.12/dist/vue.global.js"></script>
<script src="https://unpkg.com/[email protected].11/dist/vue.global.js"></script>
</head>
<body>
<div id="app">
<h1>Product goes here</h1>
<div class="nav-bar"></div>

<div class="cart">Cart({{ cart.length }})</div>
<product-display
:premium="premium"
@add-to-cart="updateCart"
@remove-from-cart="removeById"> <!-- solution -->
</product-display>
</div>

<!-- Import JS -->
<!-- Import App -->
<script src="./main.js"></script>

<!-- Import Components -->
<script src="./components/ProductDisplay.js"></script>

<!-- Mount App -->
<script>
const mountedApp = app.mount('#app')
</script>
</body>
</html>
22 changes: 21 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
const product = "Socks"
const app = Vue.createApp({
data() {
return {
cart: [],
premium: true
}
},
methods: {
updateCart(id) {
this.cart.push(id)
},
// solution
removeById(id) {
const index = this.cart.indexOf(id)
if (index > -1) {
this.cart.splice(index, 1)
}
}
// solution
}
})