2024-10-23

This commit is contained in:
gcch 2024-10-23 16:24:30 +02:00
commit 5093529cc1
427 changed files with 6691 additions and 1740 deletions

View file

@ -1,36 +1,41 @@
import { z, N } from "./index.CeK6pfoJ.js";
import { p as parse } from "./index.BgFo03XT.js";
import { R as ROUTE_API_PRODUITS } from "./api.js";
import { f as SELECTEUR_GRILLE_PRODUITS, g as SELECTEUR_BOUTON_PLUS_PRODUITS } from "./dom.js";
import { p as parse } from "./index.Dco04HYW.js";
import { R as ROUTE_API_NOUVELLE_PRODUCTS } from "./api.js";
import { f as SELECTEUR_GRILLE_PRODUITS, g as SELECTEUR_BOUTON_PLUS_PRODUITS, h as ATTRIBUT_PAGE, i as ATTRIBUT_HIDDEN } from "./dom.js";
import { h as html } from "./dom2.js";
import { l as leveServerError } from "./erreurs.js";
import { e as estReponse500 } from "./gardes.js";
import { g as getBackend, t as traiteReponseBackendWCSelonCodesHTTP } from "./reseau.js";
import { W as WCProductsArgsSchema, a as WCProductsSchema } from "./products.js";
import { W as WCV3ProductsArgsSchema, a as WCV3ProductsSchema } from "./products3.js";
import { a as recupereElementDansDocumentOuLeve } 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.DJngGX7K.js";
import { E as Either } from "./Either.wHNxn7Os.js";
import "./exports.DMCTjIlP.js";
import "./chunk-7BKSRZNG.C39W3Wne.js";
import "./exports.BuUzFliQ.js";
import "./erreurs2.js";
import "./products2.js";
import "./dom2.js";
import "./products4.js";
const ETATS_PAGE = _etats;
recupereElementDansDocumentOuLeve(SELECTEUR_GRILLE_PRODUITS);
const GRILLE_PRODUITS = recupereElementDansDocumentOuLeve(SELECTEUR_GRILLE_PRODUITS);
const BOUTON_PLUS_DE_PRODUITS = recupereElementDansDocumentOuLeve(SELECTEUR_BOUTON_PLUS_PRODUITS);
const initialisePageBoutique = () => {
BOUTON_PLUS_DE_PRODUITS.addEventListener("click", () => {
const nouvellePage = Number(GRILLE_PRODUITS.getAttribute(ATTRIBUT_PAGE)) + 1;
const args = {
page: 1
page: nouvellePage,
per_page: 13
};
Either.encase(() => parse(WCProductsArgsSchema, args)).map(
Either.encase(() => parse(WCV3ProductsArgsSchema, args)).map(
async (args2) => {
await EitherAsync(
() => getBackend({
authString: ETATS_PAGE.authString,
nonce: ETATS_PAGE.nonce,
route: ROUTE_API_PRODUITS,
route: ROUTE_API_NOUVELLE_PRODUCTS,
searchParams: new URLSearchParams(args2).toString()
})
).map((reponse) => {
console.debug("réponse", reponse);
if (estReponse500(reponse)) leveServerError("500 Server Error");
return reponse.json();
}).map(
@ -38,11 +43,48 @@ const initialisePageBoutique = () => {
// Traite tous les codes HTTPs possibles
traiteReponseBackendWCSelonCodesHTTP(
corpsReponse,
WCProductsSchema
WCV3ProductsSchema
)
)
).ifRight((donnees) => {
if (donnees.length < 12) {
BOUTON_PLUS_DE_PRODUITS.toggleAttribute(ATTRIBUT_HIDDEN);
}
const fragment = document.createDocumentFragment();
console.debug(donnees);
for (const produit of donnees.slice(0, 12)) {
pipe(
html`
<article class="produit">
<figure>
<a href="https://haikuatelier.fr.ddev.site/product/${produit.slug}">
<picture class="produit__illustration produit__illustration__principale">
${produit.images[0]?.tag}
</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">
${Number(produit.price)}
</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();