From 2c06f36534f209f032cbbe7a750cf37098bdfe81 Mon Sep 17 00:00:00 2001 From: matheus Date: Thu, 15 Dec 2022 15:26:07 -0300 Subject: [PATCH] feat(footer): api + slick --- checkout/src/arquivos/js/components/Footer.js | 104 +++++++++++++++++- 1 file changed, 98 insertions(+), 6 deletions(-) diff --git a/checkout/src/arquivos/js/components/Footer.js b/checkout/src/arquivos/js/components/Footer.js index 4fec3e3..54296a4 100644 --- a/checkout/src/arquivos/js/components/Footer.js +++ b/checkout/src/arquivos/js/components/Footer.js @@ -1,3 +1,4 @@ +import { data } from "jquery"; import { waitElement } from "m3-utils"; export default class Footer { @@ -10,16 +11,79 @@ export default class Footer { this.createPaymentsIcons(); this.createVtexpciIcon(); this.createDevIcons(); + this.onUpdate(); + this.events(); } async selectors() { //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.list = await waitElement(".footerCheckout__prateleira", { + timeout: 5000, + interval: 1000, + }); this.payments = await waitElement(".footerCheckout__payments"); this.vtexpci = await waitElement(".footerCheckout__vtexpci"); this.devIncons = await waitElement(".footerCheckout__developedBy"); + } + + fetchApiData() { + this.list.innerHTML = ` +

Você também pode gostar:

+ + `; + + fetch( + "https://m3academy.myvtex.com/api/catalog_system/pub/products/search/?fq=productClusterIds:319" + ) + .then((response) => response.json()) + .then((data) => { + //const list = document.querySelector(".footerCheckout__prateleira"); + const ul = document.createElement("ul"); + ul.classList.add("slick-test"); + this.list.appendChild(ul); + + data.map((item) => { + let colors = ""; + for (let i = 0; i < item.items.length; i++) { + console.log(colors); + colors += `

${item.items[i].name}

`; + } + const li = document.createElement("li"); + li.setAttribute("name", item.itemId); + li.classList.add("itemList"); + li.innerHTML = ` +

${item.productName}

+
+ ${colors} +
+ VER PRODUTO`; + ul.appendChild(li); + this.list.classList.add("fetch"); + ul.style.width = "100%"; + }); + }) + .then(() => { + this.addCarrossel(); + }); + } + + events() { + window.addEventListener("hashchange", () => { + if (window.location.hash == "#/cart" && this.checkoutVazio.style.display == "none") { + this.list.style.display = "flex"; + } + if (window.location.hash != "#/cart") { + this.list.style.display = "none"; + } + }); + addEventListener("resize", () => { + this.addCarrossel(); + }); + } + createPaymentsIcons() { this.payments.innerHTML = `