generated from lucien/actix-react-template
Articles section of the main page
This commit is contained in:
parent
f77b96db25
commit
9562eb98dc
5 changed files with 101 additions and 27 deletions
|
@ -1,26 +1,49 @@
|
||||||
import { Article } from '../types'
|
import { ArticlePreview } from '../types'
|
||||||
|
import Button from './Button'
|
||||||
export default function ArticleCard({ article }: { article: Article }) {
|
|
||||||
|
|
||||||
|
export default function ArticleCard({ articlePreview }: { articlePreview: ArticlePreview }) {
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
backgroundColor: 'var(--color-lightblue)',
|
backgroundColor: 'var(--color-yellow)',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
color: 'var(--color-darkblue)',
|
color: 'var(--color-black)',
|
||||||
fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif',
|
fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif',
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
lineHeight: '20px',
|
lineHeight: '20px',
|
||||||
margin: '10px',
|
margin: '20px',
|
||||||
padding: '10px',
|
padding: '1.25em',
|
||||||
|
paddingBottom: '1em',
|
||||||
|
flex: '27%',
|
||||||
|
textAlign: 'left',
|
||||||
}}>
|
}}>
|
||||||
<h2 style={{
|
<img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimages8.alphacoders.com%2F438%2F438396.jpg&f=1&nofb=1&ipt=14796576c139b58db62d2d2098392ef2fbaee77911040f7c0d98ab65a69c4644&ipo=images" alt="Article preview" style={{
|
||||||
fontSize: '20px',
|
borderRadius: '8px',
|
||||||
fontWeight: '500',
|
width: '100%',
|
||||||
margin: '0',
|
height: 'auto',
|
||||||
}}>{article.title}</h2>
|
marginBottom: '10px',
|
||||||
<p style={{
|
flexShrink: 0,
|
||||||
margin: '0',
|
}} />
|
||||||
}}>{article.content}</p>
|
<div style={{ }}>
|
||||||
|
<h2 style={{
|
||||||
|
fontSize: '25px',
|
||||||
|
fontWeight: '500',
|
||||||
|
lineHeight: '30px',
|
||||||
|
margin: '0',
|
||||||
|
padding: '0',
|
||||||
|
marginBottom: '10px',
|
||||||
|
}}>{articlePreview.title}</h2>
|
||||||
|
<p style={{
|
||||||
|
margin: '0',
|
||||||
|
padding: '0',
|
||||||
|
// limit the preview to 200 characters
|
||||||
|
overflow: 'hidden',
|
||||||
|
display: '-webkit-box',
|
||||||
|
WebkitLineClamp: 3,
|
||||||
|
lineClamp: 3,
|
||||||
|
WebkitBoxOrient: 'vertical',
|
||||||
|
}}>{articlePreview.preview}</p>
|
||||||
|
<div style={{ float: 'right', marginTop: '.5rem' }}><Button color='secondary' onClick={() => alert('Not implemented')}>Read more...</Button></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -1,22 +1,59 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import ArticleCard from "./ArticleCard";
|
import ArticleCard from "./ArticleCard";
|
||||||
import { Article } from "../types";
|
import { ArticlePreview } from "../types";
|
||||||
|
|
||||||
export default function ArticlesSection() {
|
export default function ArticlesSection() {
|
||||||
|
|
||||||
const [articles, setArticles] = useState<Article[]>([]);
|
const [articlePreviews, setArticlePreviews] = useState<ArticlePreview[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch('/api/article')
|
fetch('/api/article')
|
||||||
.then(response => response.json())
|
.then(response => {
|
||||||
.then((data: Article[]) => setArticles(data));
|
//response.json()
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
title: "Qu'est-ce que le Lorem Ipsum?",
|
||||||
|
preview: "Le Lorem Ipsum est simplement du faux texte employé dans la composition et la mise en page avant impression. Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen de polices de texte. Il n'a pas fait que survivre cinq siècles, mais s'est aussi adapté à la bureautique informatique, sans que son contenu n'en soit modifié. Il a été popularisé dans les années 1960 grâce à la vente de feuilles Letraset contenant des passages du Lorem Ipsum, et, plus récemment, par son inclusion dans des applications de mise en page de texte, comme Aldus PageMaker.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
title: "Pourquoi l'utiliser?",
|
||||||
|
preview: "On sait depuis longtemps que travailler avec du texte lisible et contenant du sens est source de distractions, et empêche de se concentrer sur la mise en page elle-même. L'avantage du Lorem Ipsum sur un texte générique comme 'Du texte. Du texte. Du texte.' est qu'il possède une distribution de lettres plus ou moins normale, et en tout cas comparable avec celle du français standard. De nombreuses suites logicielles de mise en page ou éditeurs de sites Web ont fait du Lorem Ipsum leur faux texte par défaut, et une recherche pour 'Lorem Ipsum' vous conduira vers de nombreux sites qui n'en sont encore qu'à leur phase de construction. Plusieurs versions sont apparues avec le temps, parfois par accident, souvent intentionnellement (histoire d'y rajouter de petits clins d'oeil, voire des phrases embarassantes).",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
title: "Title",
|
||||||
|
preview: "Preview",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.then((data: ArticlePreview[]) => setArticlePreviews(data));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="row" style={{
|
||||||
{articles.map(article => (
|
display: 'flex',
|
||||||
<ArticleCard key={article.id} article={article} />
|
flexWrap: 'wrap',
|
||||||
|
justifyContent: 'space-around',
|
||||||
|
backgroundColor: 'var(--color-verydarkblue)',
|
||||||
|
}}>
|
||||||
|
<h1 style={{
|
||||||
|
color: 'var(--color-yellow)',
|
||||||
|
fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif',
|
||||||
|
fontSize: '32px',
|
||||||
|
fontWeight: '500',
|
||||||
|
lineHeight: '30px',
|
||||||
|
margin: '20px',
|
||||||
|
padding: '10px',
|
||||||
|
paddingBottom: '0',
|
||||||
|
marginBottom: '10px',
|
||||||
|
textAlign: 'center',
|
||||||
|
width: '100%',
|
||||||
|
}}>Articles</h1>
|
||||||
|
{articlePreviews.map(articlePreview => (
|
||||||
|
<ArticleCard key={articlePreview.id} articlePreview={articlePreview} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,17 @@ import { ReactNode, MouseEventHandler } from 'react';
|
||||||
|
|
||||||
interface ButtonProps {
|
interface ButtonProps {
|
||||||
onClick: MouseEventHandler<HTMLButtonElement>;
|
onClick: MouseEventHandler<HTMLButtonElement>;
|
||||||
|
color: 'primary' | 'secondary';
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Button({ onClick, children }: ButtonProps) {
|
export default function Button({ onClick, color, children }: ButtonProps) {
|
||||||
return (
|
return (
|
||||||
<button style={{
|
<button style={{
|
||||||
backgroundColor: 'var(--color-lightblue)',
|
backgroundColor: color === 'primary' ? 'var(--color-yellow)' : 'var(--color-darkblue)',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
borderWidth: '0',
|
borderWidth: '0',
|
||||||
color: 'var(--color-darkblue)',
|
color: color === 'primary' ? 'var(--color-black)' : 'var(--color-white)',
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif',
|
fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif',
|
||||||
|
|
|
@ -4,6 +4,13 @@
|
||||||
--color-darkblue: #005792;
|
--color-darkblue: #005792;
|
||||||
--color-lightblue: #00bbf0;
|
--color-lightblue: #00bbf0;
|
||||||
--color-yellow: #fdb44b;
|
--color-yellow: #fdb44b;
|
||||||
|
--color-white: #ffffff;
|
||||||
|
--color-black: #000000;
|
||||||
|
--color-gray: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
|
|
|
@ -4,4 +4,10 @@ interface Article {
|
||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { Article };
|
interface ArticlePreview {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
preview: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { Article, ArticlePreview };
|
Loading…
Add table
Add a link
Reference in a new issue