From 36dae30b4eded2b102f868b0fad1087dfb9dafd1 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 5 Dec 2024 22:59:11 +0100 Subject: [PATCH] Add first version of article section --- front/src/components/ArticleCard.tsx | 26 ++++++++++++++++++++++++ front/src/components/ArticlesSection.tsx | 22 ++++++++++++++++++++ front/src/pages/MainPage.tsx | 2 ++ front/src/types.ts | 7 +++++++ 4 files changed, 57 insertions(+) create mode 100644 front/src/components/ArticleCard.tsx create mode 100644 front/src/components/ArticlesSection.tsx create mode 100644 front/src/types.ts diff --git a/front/src/components/ArticleCard.tsx b/front/src/components/ArticleCard.tsx new file mode 100644 index 0000000..96000e4 --- /dev/null +++ b/front/src/components/ArticleCard.tsx @@ -0,0 +1,26 @@ +import { Article } from '../types' + +export default function ArticleCard({ article }: { article: Article }) { + + return ( +
+

{article.title}

+

{article.content}

+
+ ) +} \ No newline at end of file diff --git a/front/src/components/ArticlesSection.tsx b/front/src/components/ArticlesSection.tsx new file mode 100644 index 0000000..5db142b --- /dev/null +++ b/front/src/components/ArticlesSection.tsx @@ -0,0 +1,22 @@ +import { useEffect, useState } from "react"; +import ArticleCard from "./ArticleCard"; +import { Article } from "../types"; + +export default function ArticlesSection() { + + const [articles, setArticles] = useState([]); + + useEffect(() => { + fetch('/api/article') + .then(response => response.json()) + .then((data: Article[]) => setArticles(data)); + }, []); + + return ( +
+ {articles.map(article => ( + + ))} +
+ ) +} \ No newline at end of file diff --git a/front/src/pages/MainPage.tsx b/front/src/pages/MainPage.tsx index 2a76825..860455e 100644 --- a/front/src/pages/MainPage.tsx +++ b/front/src/pages/MainPage.tsx @@ -1,9 +1,11 @@ +import ArticlesSection from '../components/ArticlesSection.tsx' import NavBar from '../components/NavBar.tsx' export default function MainPage() { return (
+
) } \ No newline at end of file diff --git a/front/src/types.ts b/front/src/types.ts new file mode 100644 index 0000000..2274b65 --- /dev/null +++ b/front/src/types.ts @@ -0,0 +1,7 @@ +interface Article { + id: number; + title: string; + content: string; +} + +export type { Article }; \ No newline at end of file