feat: add funcao que remove prateleira

This commit is contained in:
Mateus Antonio Rodrigues Lopes 2022-12-20 16:36:59 -03:00
parent 1bf6ecaed5
commit f1c1f16df5

View File

@ -56,22 +56,51 @@ export default class Footer {
}
onUpdate() {
const title = document.querySelector("#cart-title");
const cartTitle = document.querySelector("#cart-title");
const prateleira = document.querySelector(".footerCheckout__prateleira");
const hash = window.location.hash;
const locationHref = window.location.href;
//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 checkoutItemsQuantity = window.vtexjs.checkout.orderForm.items.length;
let target = this.checkoutVazio;
let config = { childList: true, attributes: true };
let config = { childList: true, attributes: true, attributeFilter: ["style"] };
let observer = new MutationObserver((mutations) => {
mutations.forEach(function (mutation) {
if (window.vtexjs.checkout.orderForm.items.length == 0) {
title.style.display = "none";
console.log("funcionou");
console.log(target.style.display);
if (target.style.display === "block") {
prateleira.style.display = "none";
cartTitle.style.display = "none";
} else {
prateleira.style.display = "block";
title.style.display = "block";
cartTitle.style.display = "block";
if (locationHref !== "https://m3academy.myvtex.com/checkout/#/cart") {
cartTitle.style.display = "none";
prateleira.style.display = "none";
}
window.addEventListener("hashchange", () => {
console.log(hash);
console.log(locationHref);
if (hash !== "#/cart") {
cartTitle.style.display = "none";
prateleira.style.display = "none";
}
});
}
// if (window.vtexjs.checkout.orderForm.items.length == 0) {
// cartTitle.style.display = "none";
// } else {
// cartTitle.style.display = "block";
// }
// if (hash == "email" || hash == "profile" || hash == "shipping") {
// prateleira.style.display = "none";
// } else {
// prateleira.style.display = "block";
// }
});
});