Trier les spectacles par date de création décroissante (champ date_creation StoryBlok)
This commit is contained in:
parent
b3726a01be
commit
f2667296d3
2 changed files with 13 additions and 3 deletions
|
|
@ -17,6 +17,7 @@ export interface Spectacle {
|
||||||
affiche: string;
|
affiche: string;
|
||||||
gallery: string[];
|
gallery: string[];
|
||||||
dossierPro: string;
|
dossierPro: string;
|
||||||
|
dateCreation: string;
|
||||||
_blok: SbBlokData;
|
_blok: SbBlokData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,6 +55,7 @@ export function mapStoryToSpectacle(story: any): Spectacle {
|
||||||
affiche: c.affiche?.filename || '',
|
affiche: c.affiche?.filename || '',
|
||||||
gallery: (c.galerie || []).map((a: any) => a.filename),
|
gallery: (c.galerie || []).map((a: any) => a.filename),
|
||||||
dossierPro: c.dossier?.filename || '',
|
dossierPro: c.dossier?.filename || '',
|
||||||
|
dateCreation: c.date_creation || '',
|
||||||
_blok: c,
|
_blok: c,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,17 @@ import { storyblokEditable } from '@storyblok/astro';
|
||||||
import { fetchSpectacles } from '../../lib/storyblok';
|
import { fetchSpectacles } from '../../lib/storyblok';
|
||||||
|
|
||||||
const spectacles = await fetchSpectacles();
|
const spectacles = await fetchSpectacles();
|
||||||
const jeunePublic = spectacles.filter(s => s.category === 'jeune-public' && !s.retired);
|
|
||||||
const toutPublic = spectacles.filter(s => s.category === 'tout-public' && !s.retired);
|
const byDateDesc = (a: typeof spectacles[number], b: typeof spectacles[number]) => {
|
||||||
const retraites = spectacles.filter(s => s.retired);
|
if (!a.dateCreation && !b.dateCreation) return 0;
|
||||||
|
if (!a.dateCreation) return 1;
|
||||||
|
if (!b.dateCreation) return -1;
|
||||||
|
return new Date(b.dateCreation).getTime() - new Date(a.dateCreation).getTime();
|
||||||
|
};
|
||||||
|
|
||||||
|
const jeunePublic = spectacles.filter(s => s.category === 'jeune-public' && !s.retired).sort(byDateDesc);
|
||||||
|
const toutPublic = spectacles.filter(s => s.category === 'tout-public' && !s.retired).sort(byDateDesc);
|
||||||
|
const retraites = spectacles.filter(s => s.retired).sort(byDateDesc);
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="Spectacles — Compagnie AspiRêves">
|
<Layout title="Spectacles — Compagnie AspiRêves">
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue