-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#63): create article page with content
- Loading branch information
Showing
8 changed files
with
260 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
.loader { | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
|
||
svg { | ||
width: 120px; | ||
} | ||
} | ||
|
||
.actions { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 20px 35px; | ||
} | ||
|
||
.article { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 20px; | ||
padding-bottom: 120px; | ||
|
||
> img { | ||
border-radius: 20px; | ||
} | ||
|
||
.content { | ||
padding: 0 35px; | ||
|
||
h1 { | ||
text-align: center; | ||
font-size: 18px; | ||
font-weight: bold; | ||
} | ||
|
||
.details { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 20px 0; | ||
|
||
> p { | ||
font-size: 11px; | ||
color: #7f7f7f; | ||
} | ||
|
||
.rate { | ||
display: block; | ||
width: max-content; | ||
color: white; | ||
background: var(--primary); | ||
padding: 4px 12px; | ||
border-radius: 50px; | ||
font-size: 11px; | ||
} | ||
} | ||
|
||
section { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 30px; | ||
padding-top: 30px; | ||
|
||
.infoBloc { | ||
.blocHeader { | ||
display: flex; | ||
align-items: center; | ||
gap: 22px; | ||
width: 100%; | ||
color: var(--primary); | ||
|
||
> p { | ||
font-size: 22px; | ||
font-weight: bold; | ||
} | ||
|
||
> h3 { | ||
font-size: 14px; | ||
font-weight: 500; | ||
width: 75%; | ||
line-height: 1.5; | ||
} | ||
|
||
button { | ||
border: none; | ||
background-color: white; | ||
border-radius: 50px; | ||
cursor: pointer; | ||
width: 25px; | ||
height: 25px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
outline: 1px solid var(--primary); | ||
} | ||
} | ||
|
||
ul { | ||
padding-left: 25px; | ||
padding-top: 12px; | ||
li { | ||
font-size: 12px; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
'use client'; | ||
import {useEffect, useState} from 'react'; | ||
|
||
import {format} from 'date-fns'; | ||
import Image from 'next/image'; | ||
import Link from 'next/link'; | ||
|
||
import {Loader} from '../../../src/components/decorations/Loader'; | ||
import {Navbar} from '../../../src/components/navbar/Navbar'; | ||
import {useArticleContent} from '../../../src/hook/useArticleContent'; | ||
import styles from './page.module.css'; | ||
|
||
type PageParameters = { | ||
params: { | ||
id: string; | ||
}; | ||
}; | ||
|
||
export default function Articles({params}: PageParameters) { | ||
const {id} = params; | ||
const {loading, article} = useArticleContent(id); | ||
const [formatedTitleImg, setFormatedTitleImg] = useState<string>(''); | ||
|
||
useEffect(() => { | ||
if (!loading && article) { | ||
setFormatedTitleImg( | ||
article.title | ||
.toLowerCase() | ||
.replaceAll(': ', '') | ||
.replaceAll(' ?', '') | ||
.replaceAll('’', '_') | ||
.replaceAll('&', 'et') | ||
.replaceAll(' ', '_'), | ||
); | ||
} | ||
}, [loading, article]); | ||
|
||
return ( | ||
<> | ||
<Navbar /> | ||
<div className={styles.actions}> | ||
<Link href="/articles"> | ||
<Image src="/longArrow.svg" alt="note" width={24} height={18} /> | ||
</Link> | ||
<Image src="/icons/coeur.svg" alt="coeur" width={24} height={24} /> | ||
</div> | ||
{loading && ( | ||
<div className={styles.loader}> | ||
<Loader /> | ||
</div> | ||
)} | ||
{!loading && article && ( | ||
<article className={styles.article}> | ||
<Image | ||
src={`/images/articles/${formatedTitleImg}.webp`} | ||
alt={article.title} | ||
width={360} | ||
height={185} | ||
/> | ||
|
||
<div className={styles.content}> | ||
<h1>{article.title.toUpperCase()}</h1> | ||
|
||
<div className={styles.details}> | ||
<p>{format(article.date, 'd MMM. yyyy')}</p> | ||
<span className={styles.rate}> | ||
<Image | ||
src="/icons/map/recommendations/like_blanc.svg" | ||
alt="note" | ||
width={10} | ||
height={10} | ||
/>{' '} | ||
{article.rate * 100}% | ||
</span> | ||
</div> | ||
|
||
<section> | ||
{article.content.map(({subtitle, content}, index) => ( | ||
<div key={index} className={styles.infoBloc}> | ||
<div className={styles.blocHeader}> | ||
<p>{index + 1}</p> | ||
<h3>{subtitle}</h3> | ||
<button> | ||
<Image | ||
src="/icons/coeur.svg" | ||
alt="coeur" | ||
width={17} | ||
height={17} | ||
/> | ||
</button> | ||
</div> | ||
<ul> | ||
{content.map((info, index) => ( | ||
<li key={index}>{info}</li> | ||
))} | ||
</ul> | ||
</div> | ||
))} | ||
</section> | ||
</div> | ||
</article> | ||
)} | ||
</> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {useEffect, useState} from 'react'; | ||
|
||
import {ArticleDb} from '../types/Article'; | ||
import {useArticles} from './useArticles'; | ||
|
||
export const useArticleContent = (id: string) => { | ||
const {loading, categories} = useArticles(); | ||
const [loadingArticle, setLoadingArticle] = useState<boolean>(false); | ||
const [article, setArticle] = useState<ArticleDb>(); | ||
|
||
useEffect(() => { | ||
setLoadingArticle(true); | ||
|
||
if (!loading && categories) { | ||
const allArticles: ArticleDb[] = Object.values(categories).flat(); | ||
const foundArticle = allArticles.find( | ||
(article: ArticleDb) => article.id === id, | ||
); | ||
setArticle(foundArticle); | ||
setLoadingArticle(false); | ||
} | ||
}, [loading, categories, id]); | ||
|
||
return {loading: loadingArticle, article}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters