haiku-atelier-2024/web/app/themes/haiku-atelier-2024/assets/js/scripts-page-boutique.js
gcch 900bef5aeb 2024-11-23
fonc(db) exporte la BDD de production
2024-11-23 11:06:44 +01:00

104 lines
4.5 KiB
JavaScript

import { z, N } from "./index.CeK6pfoJ.js";
import { p as parse } from "./index.DxUTT09Y.js";
import { R as ROUTE_API_NOUVELLE_PRODUCTS } from "./api.js";
import { g as SELECTEUR_BOUTON_PLUS_PRODUITS, h as SELECTEUR_GRILLE_PRODUITS, i as ATTRIBUT_ID_CATEGORIE_PRODUITS, j as ATTRIBUT_PAGE, k as ATTRIBUT_HIDDEN } from "./dom.js";
import { h as html } from "./dom2.js";
import { l as leveServerError } from "./erreurs2.js";
import { e as estReponse500 } from "./gardes.js";
import { g as getBackendAvecParametresUrl, t as traiteReponseBackendWCSelonCodesHTTP } from "./reseau.js";
import { W as WCV3ProductsArgsSchema, a as WCV3ProductsSchema } from "./products.js";
import { a as recupereElementDansDocumentOuLeve, r as recupereElementDocumentEither } from "./utils.js";
import { E as EitherAsync } from "./MaybeAsync.AE1jnxuc.js";
import { p as pipe } from "./pipe.XPB0wEfw.js";
import { t as tap } from "./index-0eef19ec.DoJSf22Z.js";
import { E as Either } from "./Either.wHNxn7Os.js";
import "./exports.B84S-6H1.js";
import "./erreurs3.js";
import "./products2.js";
import "./belt_Option-91f3b350.cBye8bLJ.js";
const ETATS_PAGE = _etats;
const GRILLE_PRODUITS = recupereElementDansDocumentOuLeve(SELECTEUR_GRILLE_PRODUITS);
const BOUTON_PLUS_DE_PRODUITS = recupereElementDocumentEither(
SELECTEUR_BOUTON_PLUS_PRODUITS
);
const initialisePageBoutique = () => {
const idCategorieProduits = GRILLE_PRODUITS.getAttribute(ATTRIBUT_ID_CATEGORIE_PRODUITS);
BOUTON_PLUS_DE_PRODUITS.ifRight((bouton) => {
bouton.addEventListener("click", () => {
const nouvellePage = Number(GRILLE_PRODUITS.getAttribute(ATTRIBUT_PAGE)) + 1;
const args = {
page: nouvellePage,
per_page: 13,
// Ajoute conditionnellement la Catégorie de Produits
...idCategorieProduits && { category: idCategorieProduits }
};
Either.encase(() => parse(WCV3ProductsArgsSchema, args)).map(
async (args2) => {
await EitherAsync(
() => getBackendAvecParametresUrl({
authString: ETATS_PAGE.authString,
nonce: ETATS_PAGE.nonce,
route: ROUTE_API_NOUVELLE_PRODUCTS,
searchParams: new URLSearchParams(args2).toString()
})
).map((reponse) => {
if (estReponse500(reponse)) leveServerError("500 Server Error");
return reponse.json();
}).map(
(corpsReponse) => (
// Traite tous les codes HTTPs possibles
traiteReponseBackendWCSelonCodesHTTP(
corpsReponse,
WCV3ProductsSchema
)
)
).ifRight((donnees) => {
if (donnees.length < 12) {
bouton.toggleAttribute(ATTRIBUT_HIDDEN);
}
const fragment = document.createDocumentFragment();
for (const produit of donnees.slice(0, 12)) {
pipe(
html`
<article class="produit">
<figure>
<a href="/product/${produit.slug}">
<picture class="produit__illustration produit__illustration__principale">
${produit.image_repos ?? ""}
</picture>
<picture class="produit__illustration produit__illustration__survol">
${produit.image_survol ?? ""}
</picture>
</a>
<figcaption class="produit__textuel">
<h3 class="produit__textuel__titre">
<a href="${produit.permalink}">${produit.name}</a>
</h3>
<p class="produit__textuel__prix">
${produit.prix_maximal}
</p>
</figcaption>
</figure>
</article>
`,
tap((article) => {
fragment.appendChild(article);
})
);
}
GRILLE_PRODUITS.appendChild(fragment);
GRILLE_PRODUITS.setAttribute(ATTRIBUT_PAGE, String(nouvellePage));
}).ifLeft((e) => {
z(e).with({ issues: N.select(), name: "ValiError" }, (problemes) => console.error("ValiError", problemes)).otherwise((e2) => console.error("Autre", e2.name, e2));
}).void();
}
);
});
});
};
document.addEventListener("DOMContentLoaded", () => {
initialisePageBoutique();
});
//# sourceMappingURL=scripts-page-boutique.js.map