From ed2bce43b8f9fd8ca5f028c99a1b131f004320c3 Mon Sep 17 00:00:00 2001 From: Marc Gavanier Date: Sat, 14 Sep 2024 00:04:04 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20flux=20actualit=C3=A9=20(#55)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(pages)/[...slug]/page.tsx | 5 +- src/app/_components/PageBuilder.tsx | 32 +-- .../_components/page-content/VerticalCard.tsx | 182 +++++++++--------- 3 files changed, 98 insertions(+), 121 deletions(-) diff --git a/src/app/(pages)/[...slug]/page.tsx b/src/app/(pages)/[...slug]/page.tsx index 9202568..40e6241 100644 --- a/src/app/(pages)/[...slug]/page.tsx +++ b/src/app/(pages)/[...slug]/page.tsx @@ -4,6 +4,8 @@ import SkipLinksPortal from '@/app/_components/SkipLinksPortal'; import NotFound from '@/app/not-found'; import { getPagesMatchingSlug, toSinglePage } from '@/api/pages'; import { contentId, defaultSkipLinks } from '@/utils/skipLinks'; +import { getBreves } from '@/api/breves'; +import { byPubicationDate } from '@/ressources/collection-operations'; export const generateMetadata = async ({ params: { slug } }: { params: { slug: string[] } }): Promise => { const page = toSinglePage(await getPagesMatchingSlug(slug)); @@ -15,6 +17,7 @@ export const generateMetadata = async ({ params: { slug } }: { params: { slug: s const Page = async ({ params: { slug } }: { params: { slug: string[] } }) => { const page = toSinglePage(await getPagesMatchingSlug(slug)); + const breves = await getBreves(); if (page == null) return ; @@ -22,7 +25,7 @@ const Page = async ({ params: { slug } }: { params: { slug: string[] } }) => { <>
- +
); diff --git a/src/app/_components/PageBuilder.tsx b/src/app/_components/PageBuilder.tsx index 76c3b2a..2e678f4 100644 --- a/src/app/_components/PageBuilder.tsx +++ b/src/app/_components/PageBuilder.tsx @@ -29,36 +29,10 @@ import { BreadCrumb } from './page-content/BreadCrumb'; import { ToolsDevicesContainer } from './page-content/ToolsDevicesContainer'; export const PageBuilder = ({ data, dataArticles, dataToolsDevices = null, slug = null, isHome }) => { - // const [fluxPublications, setFluxPublications] = useState([]); - // const [fluxActualites, setFluxActualites] = useState([]); - // const [strategiques, setStrategiques] = useState([]); - // const [recherches, setRecherch/es] = useState([]); - // const [bannerTitle, setBannerTitle] = useState(null); - // const pathname = usePathname(); - const allComponents = buildComponents(data); const struct = buildSections(allComponents); const array = struct[1] ?? []; - // useEffect(() => { - // if (dataArticles.length > 0) { - // const withoutBreves = sortArticles(dataArticles, [0]); - // const onlyStrategiques = sortArticles(dataArticles, [0, 2]); - // const onlyRecherches = sortArticles(dataArticles, [0, 1]); - // - // setFluxPublications(withoutBreves.slice(0, 2)); - // setFluxActualites(onlyBreves.slice(0, 3)); - // - // setBreves(onlyBreves); - // setStrategiques(onlyStrategiques); - // setRecherches(onlyRecherches); - // } - // }, [dataArticles]); - // - // useEffect(() => { - // setBannerTitle(null); - // }, [pathname]); - return ( <> {isHome && } @@ -115,9 +89,9 @@ export const PageBuilder = ({ data, dataArticles, dataToolsDevices = null, slug return (
- {fluxActualites && - fluxActualites.map((flux) => { - return ; + {dataArticles && + dataArticles.map(({ attributes }) => { + return ; })}
diff --git a/src/app/_components/page-content/VerticalCard.tsx b/src/app/_components/page-content/VerticalCard.tsx index 01af295..4cfdfbe 100644 --- a/src/app/_components/page-content/VerticalCard.tsx +++ b/src/app/_components/page-content/VerticalCard.tsx @@ -13,12 +13,15 @@ type ImageData = { export type CardData = { id: string; - type: 'carte-verticale' | 'autre'; + type: 'carte-verticale' | 'breve'; espacement_bas: keyof typeof marginsBottom; label?: 'Evènement' | string; nom_de_page?: string; titre_de_la_carte?: string; - image: { + texte_de_la_carte?: string; + publishedAt?: Date; + createdAt?: Date; + image?: { data: ImageData | null; }; labels: Label[]; @@ -38,103 +41,100 @@ type VerticalCardProps = { text?: string; }; -export const VerticalCard = ({ data, rows, height, width, fontsizeLabel, text }: VerticalCardProps) => { - console.log(data); - return ( - <> - {data.type !== 'carte-verticale' && ( -
-
-
-
-

{data.label}

-

- - {data.titre_de_la_carte} - -

-
-
- {data.image.data?.attributes.url && ( -
- -
- )} -
-
- )} - {data.type === 'carte-verticale' && ( +export const VerticalCard = ({ data, rows, height, width, fontsizeLabel, text }: VerticalCardProps) => ( + <> + {data.type !== 'carte-verticale' && ( +
1 ? 'center' : data.position === 'Centre' ? 'center' : '', + height: '430px', marginBottom: marginsBottom[data.espacement_bas] || '0px' }}> -
+
+
+

{data.label}

+

+ + {data.titre_de_la_carte} + +

+
+
+ {data.image?.data?.attributes.url && ( +
+ +
+ )} +
+
+ )} + {data.type === 'carte-verticale' && ( +
1 ? 'center' : data.position === 'Centre' ? 'center' : '', + marginBottom: marginsBottom[data.espacement_bas] || '0px' + }}> +
+
-
-
- {data.labels.length > 0 && - data.labels.map((label) => ( - - {label.titre_du_label} - - ))} -
-

- - {data.titre_du_lien} - -

-

- {data.texte_en_valeur} {text && text.length > 0 ? text : data.texte} -

- +
+ {data.labels.length > 0 && + data.labels.map((label) => ( + + {label.titre_du_label} + + ))}
+

+ + {data.titre_du_lien} + +

+

+ {data.texte_en_valeur} {text && text.length > 0 ? text : data.texte} +

+
- {data.image.data?.attributes.url && ( -
- -
- )}
+ {data.image?.data?.attributes.url && ( +
+ +
+ )}
- )} - - ); -}; +
+ )} + +);