rerefactor du fetching de contenus une mielleure ux au load des modales (description dans le readme)

This commit is contained in:
2025-06-26 15:26:18 +02:00
parent e85851bd4d
commit f44fbd8d06
21 changed files with 465 additions and 367 deletions

View File

@@ -122,7 +122,7 @@ export async function getRessourceItemCard(item) {
}
const relatedEtape = await REST.get(item.relationships.field_etape.links.related.href);
console.log(item);
// console.log(item);
return {

View File

@@ -0,0 +1,43 @@
import REST from '../../api/rest-axios';
import { useLayoutStore } from '../../stores/layout';
import { getPartenaires, getGouvernance, getRessources } from './multiItemPages';
export async function fetchMultiplePartialContent(contentType) {
let partialContent = {};
let pageTitle = '';
const intro = await REST.get(`/jsonapi/config_pages/intro_${contentType}/`);
const introContent = intro.data.data[0];
pageTitle =
`${introContent.attributes.field_titre} ${introContent.attributes.metatag.find(tag => tag.tag === "meta")?.attributes.content}`;
partialContent.contentTitle = introContent.attributes.field_titre;
partialContent.intro = introContent.attributes.field_intro?.value;
return { pageTitle, partialContent };
}
export async function fetchMultipleFullContent(contentType, rawContent) {
let content = {};
let multiItemPageArray = [];
switch (contentType) {
case 'ressource':
multiItemPageArray = await getRessources(rawContent);
content.ressourceTypes = new Set(multiItemPageArray.map(item => item.ressourceType));
useLayoutStore().hideEtapeList(true);
break;
case 'partenaire':
multiItemPageArray = await getPartenaires(rawContent);
break;
case 'gouvernance':
multiItemPageArray = await getGouvernance(rawContent);
break;
}
content[`${contentType}s`] = multiItemPageArray;
return content;
}

View File

@@ -0,0 +1,153 @@
import REST from '../../api/rest-axios';
import { getCleanDate, fetchFromRelationships, getRelatedEtape, getRelatedRessources } from './contentFetchUtils';
import { getCarteSensible, getTitreTexte, getChiffresCles, getDiaporama, getEntretien, getVideos, getDocument, getGallerie } from './cleanParties';
import { useLayoutStore } from '../../stores/layout';
export function fetchSingletonPartialContent(contentType, rawContent) {
let partialContent = {};
let pageTitle = rawContent.attributes.metatag.find(tag => tag.tag === "meta")?.attributes.content;
partialContent.contentTitle = rawContent.attributes.title;
if (contentType === 'etape') {
partialContent.coordinates = {
lat: rawContent.attributes.field_geofield.lat,
lon: rawContent.attributes.field_geofield.lon,
};
partialContent.adresse = rawContent.attributes.field_adresse;
partialContent.etape_number = rawContent.attributes.field_arret_numero;
partialContent.couleur = rawContent.attributes.field_couleur;
partialContent.dates = {
start: getCleanDate(rawContent.attributes.field_dates.value),
end: getCleanDate(rawContent.attributes.field_dates.end_value),
}
}
if (contentType === 'ressourceItem') {
partialContent.ressourceType = rawContent.attributes.field_type_de_ressource;
partialContent.auteurice = rawContent.attributes.field_autheurice;
partialContent.date = getCleanDate(rawContent.attributes.field_date_ressource);
}
return { pageTitle, partialContent };
}
export async function fetchSingletonFullContent(contentType, rawContent, path) {
let content = {};
const vignettePromise = fetchFromRelationships('field_vignette', rawContent.relationships);
const partiesPromise = fetchFromRelationships(contentType === 'ressourceItem' ? 'field_parties_ressource' : 'field_parties', rawContent.relationships);
let previousEtapePromise, nextEtapePromise;
if (contentType === 'etape') {
previousEtapePromise = getRelatedEtape('previous', path);
nextEtapePromise = getRelatedEtape('next', path);
content.relatedRessources = await getRelatedRessources(rawContent.id);
}
if (contentType === 'ressourceItem') {
content.introduction = rawContent.attributes.field_introduction?.processed;
if (rawContent.relationships.field_etape.data) {
const relatedEtapeFetch = fetchFromRelationships('field_etape', rawContent.relationships);
const relatedEtape = await Promise.resolve(relatedEtapeFetch);
const relatedEtapeUrl = relatedEtape.attributes.metatag.find(tag => tag.tag === "link")?.attributes.href;
content.relatedEtape = await getRelatedEtape('', relatedEtapeUrl);
}
useLayoutStore().hideEtapeList(true);
}
const [vignetteData, partiesData] = await Promise.all([vignettePromise, partiesPromise]);
if (vignetteData) {
content.vignette = {
url: {
original: vignetteData.attributes.uri.url,
small: vignetteData.attributes.image_style_uri.content_small,
medium: vignetteData.attributes.image_style_uri.content_medium,
large: vignetteData.attributes.image_style_uri.content_large,
},
alt: rawContent.relationships.field_vignette.data.meta.alt
};
}
if (partiesData) {
const partiesPromises = partiesData.map(async (partie) => {
const partieType = partie.type.replace(/^paragraph--/, "");
let partieContent = { type: partieType };
switch (partieType) {
case 'carte_sensible':
partieContent.carteSensible = await getCarteSensible(partie);
break;
case 'titre_texte':
const { titre, texte } = await getTitreTexte(partie);
partieContent.titre = titre;
partieContent.texte = texte;
break;
case 'chiffres_cles':
partieContent.chiffresCles = await getChiffresCles(partie);
break;
case 'diaporama':
partieContent.diaporama = await getDiaporama(partie);
break;
case 'entretien':
partieContent.entretien = await getEntretien(partie);
break;
case 'exergue':
partieContent.exergue = partie.attributes.field_texte_exergue.value;
break;
case 'video':
partieContent.videos = getVideos(partie);
break;
case 'document':
partieContent.document = await getDocument(partie);
break;
case 'galleries':
partieContent.gallerie = await getGallerie(partie);
break;
}
return partieContent;
});
// liens
if (rawContent.attributes.field_liens?.length) {
content.liens = [];
for (let lien of rawContent.attributes.field_liens) {
content.liens.push({
title: lien.title,
url: lien.uri,
});
}
}
// pièces jointes
if (rawContent.relationships.field_pieces_jointes?.data.length) {
content.pieces_jointes = [];
for (let pieceJointe of rawContent.relationships.field_pieces_jointes.data) {
if (pieceJointe.meta.display) {
const uuid = pieceJointe.id;
const response = await REST.get(`/jsonapi/file/file/${uuid}`);
content.pieces_jointes.push({
title: pieceJointe.meta.description,
url: response.data.data.attributes.uri.url,
});
}
}
}
content.parties = await Promise.all(partiesPromises);
}
// related étapes
if (contentType === 'etape') {
const [prevContent, nextContent] = await Promise.all([previousEtapePromise, nextEtapePromise]);
content.previous = prevContent;
content.next = nextContent;
}
return content;
}

View File

@@ -55,7 +55,7 @@ export async function getGouvernance(rawContent) {
}
export async function getRessources(rawContent) {
console.log(rawContent);
// console.log(rawContent);
const ressourcesPromises = rawContent.map(item => getRessourceItemCard(item));