From 2067739753af4d9f64ee7b0bfdface7bdf06ce02 Mon Sep 17 00:00:00 2001 From: Agustina Carrion Date: Mon, 19 Jun 2023 17:42:03 +0200 Subject: [PATCH] feat: add fetching to the news slider data wrapper --- src/components/NewsItem.tsx | 46 +++++++++++---------- src/components/NewsSlider.tsx | 2 +- src/components/NewsSliderDataWrapper.astro | 47 ++++++++++++++++------ 3 files changed, 60 insertions(+), 35 deletions(-) diff --git a/src/components/NewsItem.tsx b/src/components/NewsItem.tsx index 6b268b48..a57bbdbf 100644 --- a/src/components/NewsItem.tsx +++ b/src/components/NewsItem.tsx @@ -11,27 +11,31 @@ interface Props { const NewsItem: React.FC = ({ children, href, image, isInstagram }) => ( ); diff --git a/src/components/NewsSlider.tsx b/src/components/NewsSlider.tsx index 5fe60abd..896aa5ac 100644 --- a/src/components/NewsSlider.tsx +++ b/src/components/NewsSlider.tsx @@ -69,7 +69,7 @@ const NewsSlider: React.FC = ({ news, headline, ...props }) => {
- {news.map((item, index) => ( + {news && news.map((item, index) => ( ("../pages/en/news/*.mdx"); - -const news = rawNews - .map(({ frontmatter: { image, target, instagram, title, order = 999 } }) => { - return { - image: baseUrl + image, - target, - instagram, - title, - order, - }; - }) - .sort((a, b) => b.order - a.order); +const token = import.meta.env.PUBLIC_AIRTABLE_TOKEN; + +const options = { + method: "GET", + headers: { + Authorization: `Bearer ${token}`, + }, +}; + +const response = await fetch( + "https://api.airtable.com/v0/appXVxxSLF51bHZPf/tbl0L4qXFrr4xop8V", + options +); + +const data = await response.json(); + +let news = []; + +if (data.records && data.records.length > 0) { + news = data.records + .filter((record) => record.fields?.["Instagram URL"]) + .map((record) => { + return { + title: record.fields.Name, + target: record.fields?.["Instagram URL"], + instagram: true, + // image: record.fields?.["Selected Photos (from Event)"] + }; + }); + console.log(news); +} else { + console.log("Error"); +} + ---