diff --git a/checkout/src/arquivos/js/components/CheckoutUI.js b/checkout/src/arquivos/js/components/CheckoutUI.js index f68f3b2..3675c2e 100644 --- a/checkout/src/arquivos/js/components/CheckoutUI.js +++ b/checkout/src/arquivos/js/components/CheckoutUI.js @@ -31,10 +31,7 @@ export default class CheckoutUI { toggleFooterDropdown(event) { event.target.classList.toggle("closed"); - - event.target.nextElementSibling.classList.toggle( - "dropdown__content--closed" - ); + event.target.nextElementSibling.classList.toggle("dropdown__content--closed"); } init() { @@ -56,14 +53,7 @@ export default class CheckoutUI { resizeImages() { $(".product-image img").each((i, el) => { const $el = $(el); - $el.attr( - "src", - alterarTamanhoImagemSrcVtex( - $el.attr("src"), - this.width, - this.height - ) - ); + $el.attr("src", alterarTamanhoImagemSrcVtex($el.attr("src"), this.width, this.height)); }); } } diff --git a/checkout/src/arquivos/js/components/Footer.js b/checkout/src/arquivos/js/components/Footer.js index ddbfee7..3c3f115 100644 --- a/checkout/src/arquivos/js/components/Footer.js +++ b/checkout/src/arquivos/js/components/Footer.js @@ -7,34 +7,276 @@ export default class Footer { async init() { await this.selectors(); - // this.onUpdate(); + this.events(); + this.onUpdate(); + this.createPaymentsIcons(); + this.createVtexpciIcon(); + this.createDevIcons(); + // await this.addCarrossel(); + } + + events() { + window.addEventListener("hashchange", () => { + this.onUpdate(); + if (window.location.hash != "#/cart") { + if (document.querySelector(".footerTitle") != null) { + document.querySelector(".footerTitle").style.display = "none"; + } + + this.cartTitle.style.display = "none"; + } + if (window.location.hash == "#/cart" && this.checkoutVazio.style.display == "none") { + if (document.querySelector(".footerTitle") != null) { + document.querySelector(".footerTitle").style.display = "block"; + } + this.cartTitle.style.display = "block"; + } + console.log("HASHCHANGE FOOTER"); + 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(); + }); } 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.list = await waitElement(".footerCheckout__prateleira", { + timeout: 5000, + interval: 1000, + }); + // this.slick = await waitElement(".slick-test"); + // this.footerTitle = await waitElement(".footerTitle", { + // timeout: 5000, + // interval: 1000, + // }); + this.allList = await waitElement(".footerCheckout"); this.checkoutVazio = await waitElement(".empty-cart-content"); + this.payments = await waitElement(".footerCheckout__payments"); + this.vtexpci = await waitElement(".footerCheckout__vtexpci"); + this.devIncons = await waitElement(".footerCheckout__developedBy"); + this.listaPrateleira = await waitElement(".footerCheckout__prateleira"); + this.cartTitle = await waitElement("#cart-title"); } onUpdate() { - //Função qeu fará a verificação se o carrinho está vazio para remover a prateleira de produtos: - // vocês devem olhar a doc fornecida no Desafio para aprender a usar a MutationObserver - // sempre que o carrinho estiver vazio o elemento chcekoutVazio fica display: none e isso pode ser usado como atributo para a MutationObserver let target = this.checkoutVazio; + let lista = this.list; + + let cartTitle = this.cartTitle; + console.log("title:", cartTitle); + if (target.style.display == "none" && window.location.hash == "#/cart") { + lista.style.display = "flex"; + cartTitle.style.display = "block"; + if (!this.list.classList.contains("fetch")) { + console.log("PRIMEIRO NAO TEM FETCH"); + this.fetchApiData(); + } + } else { + lista.style.display = "none"; + cartTitle.style.display = "none"; + } let config = { childList: true, attributes: true }; let observer = new MutationObserver((mutations) => { - mutations.forEach(function (mutation) { - console.log(mutation.type); - }); + if (window.location.hash == "#/cart") { + console.log("listairai", this.list.classList); + if (!lista.classList.contains("fetch")) { + console.log("SEGUNDO NAO TEM FETCH"); + this.fetchApiData(); + } + mutations.forEach(function (mutation) { + if (target.style.display != "none") { + if (document.querySelector(".footerTitle") != null) { + document.querySelector(".footerTitle").style.display = "none"; + } + cartTitle.style.display = "none"; + lista.style.display = "none"; + } else { + if (document.querySelector(".footerTitle") != null) { + document.querySelector(".footerTitle").style.display = "block"; + } + lista.style.display = "flex"; + cartTitle.style.display = "block"; + } + console.log(mutation.type); + }); + } }); observer.observe(target, config); } + async addCarrossel() { - const elemento = await waitElement("#my-element"); - $(elemento).slick({ - slidesToShow: 4, - slidesToScroll: 1, - }); + console.log("start slick"); + const elemento = await waitElement(".slick-test"); + if ($(elemento).hasClass("slick-initialized")) { + $(elemento).slick("unslick"); + } + if (window.innerWidth > 1024) { + $(elemento).not(".slick-initialized").slick({ + slidesToShow: 4, + slidesToScroll: 1, + }); + } else if (window.innerWidth > 375) { + $(elemento).not(".slick-initialized").slick({ + slidesToShow: 3, + slidesToScroll: 1, + }); + } else if (window.innerWidth <= 375) { + $(elemento).not(".slick-initialized").slick({ + slidesToShow: 2, + slidesToScroll: 1, + }); + } + + console.log("end slick"); + } + + fetchApiData() { + console.log("COMEÇO FETCH"); + fetch( + "https://m3academy.myvtex.com/api/catalog_system/pub/products/search/?fq=productClusterIds:319" + ) + .then((response) => response.json()) + .then((data) => { + console.log(data); + const ul = document.createElement("ul"); + + ul.classList.add("slick-test"); + this.list.appendChild(ul); + const footerCheckout = document.querySelector(".footerCheckout"); + const footerTitle = document.createElement("p"); + footerTitle.classList.add("footerTitle"); + footerTitle.innerText = "Você também pode gostar:"; + footerCheckout.insertBefore(footerTitle, this.list); + 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}
+