Skip to content

Commit

Permalink
Merge pull request #35 from betagouv/maud/homepage_articles
Browse files Browse the repository at this point in the history
Use grist to display homepage articles
  • Loading branch information
jillro authored Nov 13, 2024
2 parents ec7ba94 + d46570d commit fb70267
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 64 deletions.
80 changes: 19 additions & 61 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { fr } from "@codegouvfr/react-dsfr";
import AutocompleteSearch from "@/components/AutocompleteSearch";
import Link from "next/link";
import Card from "@codegouvfr/react-dsfr/Card";
import { getArticles } from "@/data/articles";

export default async function Page() {
const articles = (await getArticles()).filter(({ homepage }) => homepage);

return (
<>
<div className={fr.cx("fr-container", "fr-pt-4w", "fr-pb-4w")}>
Expand All @@ -30,67 +33,22 @@ export default async function Page() {
</h2>
</div>
<div className={fr.cx("fr-col-md-6")}>
<p>
<Link
href="#"
className={fr.cx(
"fr-link",
"fr-link--icon-left",
"fr-icon-arrow-right-line",
)}
>
Je suis enceinte, quelles précautions prendre&nbsp;?
</Link>
</p>
<p>
<Link
href="#"
className={fr.cx(
"fr-link",
"fr-link--icon-left",
"fr-icon-arrow-right-line",
)}
>
Je ne me sens plus malade, est ce que je peux arrêter mon
traitement&nbsp;?
</Link>
</p>
<p>
<Link
href="#"
className={fr.cx(
"fr-link",
"fr-link--icon-left",
"fr-icon-arrow-right-line",
)}
>
Dois-je me faire vacciner contre la grippe saisonnière&nbsp;?
</Link>
</p>
<p>
<Link
href="#"
className={fr.cx(
"fr-link",
"fr-link--icon-left",
"fr-icon-arrow-right-line",
)}
>
Que faire si j&apos;ai des effets indésirables&nbsp;?
</Link>
</p>
<p>
<Link
href="#"
className={fr.cx(
"fr-link",
"fr-link--icon-left",
"fr-icon-arrow-right-line",
)}
>
Numéros d&apos;urgence
</Link>
</p>
<ul role="nav" className={fr.cx("fr-raw-list")}>
{articles.map(({ title, slug }) => (
<li key={slug} className={fr.cx("fr-mb-3w")}>
<Link
href={`/articles/${slug}`}
className={fr.cx(
"fr-link",
"fr-link--icon-left",
"fr-icon-arrow-right-line",
)}
>
{title}
</Link>
</li>
))}
</ul>
</div>
<div
className={fr.cx(
Expand Down
2 changes: 2 additions & 0 deletions src/data/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function getArticles() {
"Source",
"Contenu",
"Theme",
"Homepage",
]);

return records.map(({ fields }) => {
Expand All @@ -17,6 +18,7 @@ export async function getArticles() {
source: fields.Source as string,
content: fields.Contenu as string,
category: fields.Theme as string,
homepage: fields.Homepage as boolean,
};
});
}
6 changes: 3 additions & 3 deletions src/data/grist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const gristCache = new Map<string, Promise<any>>();
export const getGristTableData = <F extends string>(
tableId: string,
fields: F[],
): Promise<{ id: number; fields: Record<F, string | number> }[]> => {
): Promise<{ id: number; fields: Record<F, string | number | boolean> }[]> => {
if (!gristCache.has(tableId)) {
gristCache.set(tableId, uncachedGetGristTableData(tableId, fields));
}
Expand All @@ -24,9 +24,9 @@ export const getGristTableData = <F extends string>(
async function uncachedGetGristTableData<F extends string>(
tableId: string,
fields: F[],
): Promise<{ id: number; fields: Record<F, string | number> }[]> {
): Promise<{ id: number; fields: Record<F, string | number | boolean> }[]> {
const response = await fetch(
`https://grist.numerique.gouv.fr/api/docs/${process.env.GRIST_DOC_ID}/tables/${tableId}/records`,
`https://grist.numerique.gouv.fr/api/docs/${process.env.GRIST_DOC_ID}/tables/${tableId}/records?sort=manualSort`,
{
headers: {
Authorization: `Bearer ${process.env.GRIST_API_KEY}`,
Expand Down

0 comments on commit fb70267

Please sign in to comment.