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;
|
||||
gallery: string[];
|
||||
dossierPro: string;
|
||||
dateCreation: string;
|
||||
_blok: SbBlokData;
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +55,7 @@ export function mapStoryToSpectacle(story: any): Spectacle {
|
|||
affiche: c.affiche?.filename || '',
|
||||
gallery: (c.galerie || []).map((a: any) => a.filename),
|
||||
dossierPro: c.dossier?.filename || '',
|
||||
dateCreation: c.date_creation || '',
|
||||
_blok: c,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,17 @@ import { storyblokEditable } from '@storyblok/astro';
|
|||
import { fetchSpectacles } from '../../lib/storyblok';
|
||||
|
||||
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 retraites = spectacles.filter(s => s.retired);
|
||||
|
||||
const byDateDesc = (a: typeof spectacles[number], b: typeof spectacles[number]) => {
|
||||
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">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue