generated from lucien/actix-react-template
Add first version of article section
This commit is contained in:
parent
5c4ac78dee
commit
36dae30b4e
4 changed files with 57 additions and 0 deletions
26
front/src/components/ArticleCard.tsx
Normal file
26
front/src/components/ArticleCard.tsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { Article } from '../types'
|
||||
|
||||
export default function ArticleCard({ article }: { article: Article }) {
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
backgroundColor: 'var(--color-lightblue)',
|
||||
borderRadius: '8px',
|
||||
color: 'var(--color-darkblue)',
|
||||
fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif',
|
||||
fontSize: '14px',
|
||||
lineHeight: '20px',
|
||||
margin: '10px',
|
||||
padding: '10px',
|
||||
}}>
|
||||
<h2 style={{
|
||||
fontSize: '20px',
|
||||
fontWeight: '500',
|
||||
margin: '0',
|
||||
}}>{article.title}</h2>
|
||||
<p style={{
|
||||
margin: '0',
|
||||
}}>{article.content}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
22
front/src/components/ArticlesSection.tsx
Normal file
22
front/src/components/ArticlesSection.tsx
Normal file
|
@ -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<Article[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/article')
|
||||
.then(response => response.json())
|
||||
.then((data: Article[]) => setArticles(data));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{articles.map(article => (
|
||||
<ArticleCard key={article.id} article={article} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
import ArticlesSection from '../components/ArticlesSection.tsx'
|
||||
import NavBar from '../components/NavBar.tsx'
|
||||
|
||||
export default function MainPage() {
|
||||
return (
|
||||
<div>
|
||||
<NavBar />
|
||||
<ArticlesSection />
|
||||
</div>
|
||||
)
|
||||
}
|
7
front/src/types.ts
Normal file
7
front/src/types.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
interface Article {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export type { Article };
|
Loading…
Add table
Add a link
Reference in a new issue