feat(Footer.js): api das prateleiras,com o slick não funcional

This commit is contained in:
Ramon Dias Ferreira 2022-12-15 23:55:03 -03:00
parent 30555d9098
commit d29c433a4d

View File

@ -3,17 +3,55 @@ import { waitElement } from "m3-utils";
export default class Footer {
constructor() {
this.init();
this.requestShelf();
this.addCarrossel();
}
async init() {
await this.selectors();
// this.onUpdate();
this.requestShelf();
this.addCarrossel();
}
async selectors() {
this.itensShelf = await waitElement(".footerCheckout__prateleira", {
timeout: 5000,
interval: 1000})
// this.itensShelf = await waitElement(".empty-cart-content")
//Para verificar se o carrinho está vazio e remover a prateleira de produtos:
// vocês devem olhar a doc fornecida no Desafio para aprender a usar o waitElement
this.checkoutVazio = await waitElement(".empty-cart-content");
// this.checkoutVazio = await waitElement(".container-cart", {
// });
}
requestShelf() {
let prateleira= this.itensShelf;
prateleira.innerHTML = `
<p class="footerChekout__prateleira-title">Você também pode gostar</p>
<ul class="carrosel-ul"></ul>
`;
const api = "https://m3academy.myvtex.com/api/catalog_system/pub/products/search/?fq=productClusterIds:319";
const prodUl = document.querySelector("carrosel-ul")
fetch(api)
.then((response) => response.json())
.then(function(data) {
return data.map(function(item) {
let li = document.createElement("li")
li.setAttribute("id", item.productId)
li.innerHTML = `
<img src="${item.items[0].images[0].imageUrl}" alt="${item.productName}" />
<p class="product-name">${item.productName}</p>
<div class="product-variation">${item.items.map((name) => {
return `<a name="product-variationvariation" class="product-variationvariation">${name.name}</a>`
}).join("")}</div>
<button class="show-product">Ver produto</button>
`;
prateleira.children[1].appendChild(li);
});
});
}
onUpdate() {
@ -31,10 +69,13 @@ export default class Footer {
observer.observe(target, config);
}
async addCarrossel() {
const elemento = await waitElement("#my-element");
const elemento = await waitElement(".carrosel-ul");
$(elemento).slick({
slidesToShow: 4,
slidesToScroll: 1,
arrows: true,
variableWidth: true,
infinite: false,
});
}
}