Skip to content

Commit

Permalink
fix: ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pReya committed Oct 9, 2023
1 parent b700639 commit ddb44e0
Show file tree
Hide file tree
Showing 12 changed files with 1,749 additions and 7,098 deletions.
8,586 changes: 1,588 additions & 6,998 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "astro dev --host",
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
},
Expand All @@ -26,5 +26,9 @@
"rehype-slug": "^6.0.0",
"tailwindcss": "^3.3.3",
"vite-plugin-svgr": "^3.3.0"
},
"dependencies": {
"@astrojs/check": "^0.2.0",
"typescript": "^5.2.2"
}
}
17 changes: 10 additions & 7 deletions src/components/AcademyIndexLoader.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Course } from "@components";
import { transformAcademy } from "@util/ContentTransformer";
import type { AcademyPageFrontmatter } from "@interfaces/IAcademy";
import type { ICourse } from "@components/Course";
const { language = "en" } = Astro.props;
Expand All @@ -22,18 +23,20 @@ const coursesAndLessons = transformAcademy(rawAcademyContent);

{
Object.values(coursesAndLessons).map((course) => {
const lessons = course.children.map((child) => ({
const lessons = course?.children?.map((child) => ({
title: child.frontmatter.title,
target: child.url,
}));
return (
<Course
course={{
title: course.frontmatter.title,
img: course.frontmatter.img,
imgAlt: course.frontmatter.imgAlt,
items: lessons,
}}
course={
{
title: course.frontmatter.title,
img: course.frontmatter.img,
imgAlt: course.frontmatter.imgAlt,
items: lessons,
} as ICourse
}
/>
);
})
Expand Down
14 changes: 8 additions & 6 deletions src/components/Course.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import React from "react";
import { ReactComponent as ArrowIcon } from "@assets/arrow.svg";
import GithubSlugger from "github-slugger";

export interface ICourse {
title: string;
img: string;
imgAlt?: string;
items: { target: string; title: string }[] | null;
}

interface Props {
className?: string;
course: {
title: string;
img: string;
imgAlt?: string;
items: { target: string; title: string }[] | null;
};
course: ICourse;
}

const Course: React.FC<Props> = ({ className, course }) => {
Expand Down
20 changes: 13 additions & 7 deletions src/components/InterventionsMapSection.astro
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ const trimmedAndSorted = trimAndSortInterventions(
Latest Interventions
</div>
<div class="text-base md:hidden">
When we go to place to <strong>support a project, build a maker space or perform a workshop, we call that an intervention.</strong> Every intervention has its unique partners, goals and outcomes, but every intervention <strong>helps to strengthen the ecosystem of the Ukraine.</strong>
When we go to place to <strong
>support a project, build a maker space or perform a workshop, we call
that an intervention.</strong
> Every intervention has its unique partners, goals and outcomes, but
every intervention <strong
>helps to strengthen the ecosystem of the Ukraine.</strong
>
</div>
</div>
<div
Expand All @@ -42,12 +48,12 @@ const trimmedAndSorted = trimAndSortInterventions(
{
trimmedAndSorted.map((intervention) => (
<InterventionPreviewCard
href={intervention.url}
image={intervention.frontmatter.images[0]}
date={intervention.frontmatter.date}
title={intervention.frontmatter.title}
location={intervention.frontmatter.location}
tags={intervention.frontmatter.tags}
href={intervention?.url || ""}
image={intervention?.frontmatter?.images?.[0] || ""}
date={intervention?.frontmatter?.date}
title={intervention?.frontmatter?.title}
location={intervention?.frontmatter?.location}
tags={intervention?.frontmatter?.tags}
/>
))
}
Expand Down
80 changes: 25 additions & 55 deletions src/components/NewsSliderDataWrapper.astro
Original file line number Diff line number Diff line change
@@ -1,62 +1,32 @@
---
import { NewsSliderComponent } from "@components";
import { writeFileSync } from "fs";
import { getNewsItems } from "@util/AirTable";
import type { INewsItem } from "@interfaces/INews";
const { headline, id, ...rest } = Astro.props;
const AIRTABLE_BASE_URL = "https://api.airtable.com/v0/";
const token = import.meta.env.PUBLIC_AIRTABLE_TOKEN;
const options = {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
};
const response = await fetch(
AIRTABLE_BASE_URL + "appy8mE1ZpLXfYzEQ/tblvfXTgnme0tqIQD",
options
);
const data = await response.json();
let news = [];
if (data.records && data.records.length > 0) {
try {
writeFileSync(
"./fetch.json",
JSON.stringify(data.records)
);
// file written successfully
} catch (err) {
console.error("Error while writing file", err);
}
news = data.records
// has Instagram URL
.filter((record) => record.fields?.["Instagram URL"])
// has status "live"
.filter((record) => record.fields?.["Status"] === "live")
// is of media type "photo"
.filter((record) => record.fields?.["Media type"]?.includes("photo"))
// has images
.filter((record) => record.fields?.["Selected Photos (from Event)"]?.length)
.map((record) => {
return {
title: record.fields.Name,
target: record.fields?.["Instagram URL"],
instagram: true,
image:
record.fields?.["Selected Photos (from Event)"]?.[0].thumbnails?.[
"large"
]?.url,
};
});
console.log("NEWS", news);
} else {
console.log("Error");
}
const data = await getNewsItems();
const news = data
// has Instagram URL
?.filter((record) => record.fields?.["Instagram URL"])
// has status "live"
.filter((record) => record.fields?.["Status"] === "live")
// is of media type "photo"
.filter((record) => record.fields?.["Media type"]?.includes("photo"))
// has images
.filter((record) => record.fields?.["Selected Photos (from Event)"]?.length)
.map((record) => {
return {
title: record.fields.Name,
target: record.fields?.["Instagram URL"],
instagram: true,
image:
record.fields?.["Selected Photos (from Event)"]?.[0].thumbnails?.[
"large"
]?.url,
} as INewsItem;
}).splice(30);
---

<NewsSliderComponent {news} {headline} {id} {...rest} client:idle />
<NewsSliderComponent news={news || []} {headline} {id} {...rest} client:idle />
2 changes: 1 addition & 1 deletion src/layouts/AcademyContent.astro
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const localeFromUrl =
title={frontmatter?.title}
teaser={frontmatter?.teaser}
category={parentPage?.frontmatter?.title}
img={frontmatter?.img || parentPage.frontmatter?.img}
img={frontmatter?.img || parentPage?.frontmatter?.img}
/>
</div>
<div
Expand Down
12 changes: 6 additions & 6 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ const localeFromUrl = Astro?.url?.pathname
const rawMenus = await Astro.glob<IMenuMarkdown>("../pages/**/_menu.mdx");
const translatedMenu = rawMenus.find((rawMenu) =>
rawMenu.url
.split("/")
const translatedMenu = rawMenus?.find((rawMenu) =>
rawMenu?.url
?.split("/")
.filter(Boolean)
.map((urlPart) => urlPart.toLowerCase())
.includes(localeFromUrl)
).frontmatter?.menu;
)?.frontmatter?.menu;
const translatedAndRebasedMenu = translatedMenu.map((menuItem) => ({
const translatedAndRebasedMenu = translatedMenu?.map((menuItem) => ({
...menuItem,
target: baseUrl === "/" ? menuItem.target : baseUrl + menuItem.target,
}));
const isProduction = import.meta.env.MODE === "production";
---

<!DOCTYPE html>
<!doctype html>
<html lang={localeFromUrl} class="scroll-smooth h-full">
<head>
<meta charset="UTF-8" />
Expand Down
16 changes: 9 additions & 7 deletions src/layouts/InterventionIndex.astro
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const trimmedAndSorted = trimAndSortInterventions(rawInterventionsContent);
title={intervention.frontmatter?.title}
teaser={intervention.frontmatter?.teaser}
tags={[
intervention.frontmatter?.tags?.[0],
intervention.frontmatter?.tags?.[1],
intervention.frontmatter?.tags?.[0] || "",
intervention.frontmatter?.tags?.[1] || "",
]}
date={intervention.frontmatter?.date}
location={intervention.frontmatter?.location}
Expand Down Expand Up @@ -66,18 +66,20 @@ const trimmedAndSorted = trimAndSortInterventions(rawInterventionsContent);
bg={4}
target="mailto:[email protected]"
actionCaption="Get in contact"
>Schools, universities, NGOs, Startups and other organizations can reach
out to us to request the Tolocars for projects, workshops and trainings.</Card
>
Schools, universities, NGOs, Startups and other organizations can reach
out to us to request the Tolocars for projects, workshops and trainings.
</Card>
<Card
title="You are a Maker and want to partner with us?"
bg={5}
target="mailto:[email protected]"
actionCaption="Get in contact"
>We are looking for Makers, FabLabs, Hackerspaces, Makerspaces and other
Communities who wants to partner with us in the Ukraine and
internationally over the internet.</Card
>
We are looking for Makers, FabLabs, Hackerspaces, Makerspaces and other
Communities who wants to partner with us in the Ukraine and
internationally over the internet.
</Card>
</CardContainer>
</ContentSection>
</BaseLayout>
16 changes: 8 additions & 8 deletions src/layouts/InterventionSingleView.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
InterventionSingleViewHeading,
} from "@components";
const { frontmatter, url, file, headings } = Astro.props;
const { frontmatter } = Astro.props;
const rawInterventionsContent = await Astro.glob<IInterventionFrontmatter>(
"../pages/en/interventions/*.mdx"
Expand All @@ -20,7 +20,7 @@ const rawInterventionsContentWithoutIndex = rawInterventionsContent.filter(
const relatedInterventions = rawInterventionsContentWithoutIndex.filter(
(interventionFromFilesystem) =>
frontmatter.related?.some((slug) =>
frontmatter.related?.some((slug: string) =>
interventionFromFilesystem.url?.includes(slug)
)
);
Expand Down Expand Up @@ -55,12 +55,12 @@ const relatedInterventions = rawInterventionsContentWithoutIndex.filter(
{
relatedInterventions.map((intervention) => (
<InterventionPreviewCard
href={intervention.url}
image={intervention.frontmatter.images[0]}
date={intervention.frontmatter.date}
title={intervention.frontmatter.title}
location={intervention.frontmatter.location}
tags={intervention.frontmatter.tags}
href={intervention?.url || ""}
image={intervention?.frontmatter?.images?.[0] || ""}
date={intervention?.frontmatter?.date}
title={intervention?.frontmatter?.title}
location={intervention?.frontmatter?.location}
tags={intervention?.frontmatter?.tags}
/>
))
}
Expand Down
73 changes: 73 additions & 0 deletions src/util/AirTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import fs from "node:fs";

const AIRTABLE_BASE_URL = "https://api.airtable.com/v0/";
const AIRTABLE_BASE_ID = "appy8mE1ZpLXfYzEQ/tblvfXTgnme0tqIQD";

const token = import.meta.env.PUBLIC_AIRTABLE_TOKEN;

const commonHeaders = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};

interface AirtableResponse {
records: Array<{
id?: string;
createdTime?: string;
fields: {
Name?: string;
"Instagram URL"?: string;
Status?: string;
"Media type"?: Array<string>;
"Selected Photos (from Event)"?: Array<{
id?: string;
url?: string;
thumbnails?: {
small?: { url?: string };
medium?: { url?: string };
large?: { url?: string };
};
}>;
Type?: Array<string>;
};
}>;
}

const fetchAndHandleErrors = async <T>(
resource: RequestInfo,
options?: RequestInit
): Promise<T> => {
const response = await fetch(AIRTABLE_BASE_URL + resource, {
...options,
headers: {
...options?.headers,
...commonHeaders,
},
});

console.log(JSON.stringify(response));

if (!response.ok) {
const text = await response.text();
console.error("Server returned Error: " + text);
throw new Error("Server returned Error: " + text);
}

return response.json();
};

export const getNewsItems = async () => {
const { records } = await fetchAndHandleErrors<AirtableResponse>(
AIRTABLE_BASE_ID
);

if (records && records.length > 0) {
try {
fs.writeFileSync("./fetch.json", JSON.stringify(records));
// file written successfully
} catch (err) {
console.error("Error while writing file", err);
}
return records;
}
};
Loading

0 comments on commit ddb44e0

Please sign in to comment.