Merge pull request 'feature/footer' (#1) from feature/footer into develop

Reviewed-on: #1
This commit is contained in:
Ramon Dias Ferreira 2022-12-18 23:54:58 +00:00
commit 2f898b3d12
3 changed files with 193 additions and 11 deletions

View File

@ -6,35 +6,173 @@ export default class Footer {
}
async init() {
this.list = await this.requestApi();
await this.selectors();
// this.onUpdate();
if (window.location.hash === "#/cart") {
await this.shelfUpdate();
}
this.shelfList = await waitElement(".footerCheckout__shelfList");
this.shelfItens();
this.events();
this.addCarrossel();
this.creditCardIconsHTML();
this.developedByIconsHTML();
}
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.itensShelf = await waitElement(".footerCheckout__prateleira");
this.checkoutVazio = await waitElement(".empty-cart-content");
this.creditCardIcons = await waitElement(".footerCheckout__stamps");
this.developedByIcons = await waitElement(".footerCheckout__developedBy");
}
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
createShelf() {
if(this.itensShelf) {
this.itensShelf.innerHTML = `
<div class="footerCheckout__prateleira-title">
<h2>Você também pode gostar:</h2>
</div>
<ul class="footerCheckout__shelfList"></ul>
`
}
}
shelfItens() {
let structure = "";
this.list.forEach((response) => {
const sku = response.skus.map((item) => `<li>${item}</li>`);
structure += `
<li class="liItens">
<figure><img src ="${response.img}"/></figure>
<figcaption>${response.name}</figcaption>
<div><ul>${sku}</ul></div>
<button type="button"><a href="${response.link}">Ver Produto</a></button>
</li>
`
})
this.shelfList.innerHTML = structure
}
async requestApi() {
const api =
"https://m3academy.myvtex.com/api/catalog_system/pub/products/search/?fq=productClusterIds:319";
return fetch(api)
.then((response) => response.json())
.then((data) => {
const prodInfo = data.map((response) => ({
name: response.productName,
skus: response.items.map((item) => item.name),
img: response.items[0].images[0].imageUrl,
link: response.link,
}));
return prodInfo
});
}
events() {
window.addEventListener("hashchange", this.hashChange.bind(this))
}
async shelfUpdate() {
let target = this.checkoutVazio;
let config = { childList: true, attributes: true };
let observer = new MutationObserver((mutations) => {
mutations.forEach(function (mutation) {
console.log(mutation.type);
mutations.map((mutation) => {
console.log(mutation.target.attributes.style.nodeValue);
if(mutation.target.attributes.style.nodeValue == "display: none;") {
this.createShelf();
} else if (mutation.target.attributes.style.nodeValue == "display: block;") {
this.removeShelf();
}
});
});
observer.observe(target, config);
}
hashChange(e) {
if(e.newURL !== "https://m3academy.myvtex.com/checkout/#/cart") {
this.itensShelf.classList.add("desativado");
} else {
this.itensShelf.classList.remove("desativado");
}
}
async addCarrossel() {
const elemento = await waitElement("#my-element");
const elemento = await waitElement(".footerCheckout__shelfList");
$(elemento).slick({
slidesToShow: 4,
slidesToScroll: 1,
arrows: true,
infinite: false,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 1,
}
},
{
breakpoint: 375,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
},
{
breakpoint: 290,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
]
});
}
creditCardIconsHTML() {
this.creditCardIcons.innerHTML = `
<li class="credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/masterCardM3Academy.png" alt="Mastercard"></li>
<li class="credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/visaM3Academy.png" alt=""></li>
<li class="credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/amexM3Academy.png" alt="American Express"></li>
<li class="credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/eloM3Academy.png" alt="Elo"></li>
<li class="credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/hiperCardM3Academy.png" alt="Hipercard"></li>
<li class="credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/payPalM3Academy.png" alt="PayPal"></li>
<li class="credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/boletoM3Academy.png" alt="Boleto"></li>
<li><span class="footerCheckout__stamps__divider"></span></li>
<li class="vtex-pci credit-card"><img src="https://agenciamagma.vteximg.com.br/arquivos/vtexPCIM3Academy.png" alt="PCI VTEX"></li>
`;
}
developedByIconsHTML() {
this.developedByIcons.innerHTML = `
<li>
<div class="by-vtex">
<a href="https://vtex.com.br-pt/">
<span>Powered By</span>
</a>
<img class="vtex-logo" src="https://agenciamagma.vteximg.com.br/arquivos/logoVTEXM3Academy.png" alt="VTEX" />
</div>
</li>
<li>
<div class="by-m3">
<a href="https://vtex.com.br-pt/">
<span>Developed By</span>
</a>
<img class="m3-logo" src="https://agenciamagma.vteximg.com.br/arquivos/logoM3M3Academy.png" alt="M3" />
</div>
</li>
`;
}
removeShelf() {
this.itensShelf.innerHTML = "";
}
}

View File

@ -8,6 +8,9 @@
padding: 0 16px;
}
}
&-message {
display: none;
}
&-title {
font-size: 20px;

View File

@ -3,10 +3,48 @@
border-top: none;
color: $color-gray2;
&__prateleira{
.footerCheckout__prateleira-title {
display: flex;
justify-content: center;
}
}
&__wrapper {
align-items: center;
display: flex;
justify-content: space-between;
padding-top: 56px;
.container {
display: flex;
justify-content: space-between;
.footerCheckout__address{
width: 21.02%;
left: 2.5%;
}
.footerCheckout__stamps {
width: 31.56%;
}
.footerCheckout__developedBy{
display: flex;
width: 16.95%;
right: 2.5%;
.by-vtex, .by-m3{
display: flex;
.vtex-logo, .m3-logo{
width: 50% ;
}
}
}
}
}
&__address {
@ -71,4 +109,7 @@
}
}
}
.desativado {
display: none !important;
}
}