Last active
October 18, 2017 16:20
-
-
Save candidosales/70c5bd51e5ffcf981f5929e17f689565 to your computer and use it in GitHub Desktop.
ZX
This file contains hidden or 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
export default function productList(products) { | |
const element = document.getElementById('product-list'); | |
// map of products | |
let productItem = products.map(product => ` | |
<div class="product-item"> | |
<h1 class="product-title">${product.productVariants[0].title}</h1> | |
<img class="product-image" src="${product.productVariants[0].imageUrl}" alt="${product.productVariants[0].title}"> | |
<p class="product-price">${product.productVariants[0].price}</p> | |
<button class="less">-</button> | |
<input type="text" class="item-amount" value="1"></input> | |
<button class="more">+</button> | |
</div>`).join(''); | |
// append list to html | |
element.innerHTML = productItem; | |
} |
This file contains hidden or 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
export class ProductListComponent { | |
constructor(productService) { | |
this.productService = new ProductService(); | |
this.init(); | |
} | |
function init() { | |
this.productService.getProduct('storeId') | |
.then({ function (data) { | |
let storeId = data.data.pocSearch[0].id; | |
// call productService function | |
buildTemplate(storeId); | |
}) | |
.catch(error => console.error('TODO: tratar erro ', error)); | |
} | |
function buildTemplate(products) { | |
const element = document.getElementById('product-list'); | |
// map of products | |
let productItem = products.map(product => ` | |
<div class="product-item"> | |
<h1 class="product-title">${product.productVariants[0].title}</h1> | |
<img class="product-image" src="${product.productVariants[0].imageUrl}" alt="${product.productVariants[0].title}"> | |
<p class="product-price">${product.productVariants[0].price}</p> | |
<button class="less">-</button> | |
<input type="text" class="item-amount" value="1"></input> | |
<button class="more">+</button> | |
</div>`).join(''); | |
// append list to html | |
element.innerHTML = productItem; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment