-
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.
- Loading branch information
1 parent
9ffb9bf
commit 9f5e407
Showing
5 changed files
with
80 additions
and
71 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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import { headers } from 'next/headers' | ||
|
||
import Renderer from './renderer'; | ||
import { getArticles } from '../api/articles'; | ||
import { Article, ArticleResponseWithCount } from '../models/article'; | ||
import { getRequestContext } from '../utils/requestContext'; | ||
|
||
export default async function Page() { | ||
const { props } = await get(); | ||
return <Renderer {...props} />; | ||
} | ||
|
||
// export async function get(ctx: any) { | ||
export async function get() { | ||
const response: Response = await getArticles(1, 5, getRequestContext(headers())); | ||
// ctx.res.statusCode = response.status; | ||
|
||
let articlesResponseWithCount: ArticleResponseWithCount = null; | ||
let articles: Array<Article> = []; | ||
if (response.status === 200) { | ||
articlesResponseWithCount = await response.json() as ArticleResponseWithCount; | ||
articles = articlesResponseWithCount.articles.map(article => { | ||
return { | ||
path: article.path, | ||
title: article.title, | ||
content: `${article.content} ...`, | ||
publishedAt: article.publishedAt, | ||
updatedAt: article.updatedAt | ||
} as Article | ||
}); | ||
} | ||
|
||
return { | ||
props: { | ||
statusCode: response.status, | ||
articles: articles | ||
} | ||
} | ||
} |
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,40 @@ | ||
import { Article } from '../models/article'; | ||
import HeadMetaComponent from '../components/headmeta'; | ||
import CoverWithNavigationComponent from '../components/cover/withNavigation'; | ||
import RecentArticlesComponent from '../components/recentArticles'; | ||
import styles from '../styles/home.module.scss'; | ||
import containerStyles from '../styles/components/container.module.scss'; | ||
import { defaultRobotsMeta } from '../../config'; | ||
import PlanePage from '../components/planePage'; | ||
|
||
const Renderer: React.FunctionComponent<{ | ||
statusCode: number, | ||
articles: Array<Article> | ||
}> = ({ statusCode, articles }) => { | ||
if (statusCode !== 200) { | ||
return <PlanePage | ||
title={statusCode.toString()} | ||
content="Something went to wrong..." | ||
/> | ||
} | ||
|
||
return ( | ||
<> | ||
<HeadMetaComponent | ||
robotsMeta={defaultRobotsMeta} | ||
/> | ||
<CoverWithNavigationComponent | ||
contentCover={null} | ||
/> | ||
<main> | ||
<div className={`${containerStyles.container} ${styles.wrap}`} > | ||
<RecentArticlesComponent | ||
articles={articles} | ||
/> | ||
</div> | ||
</main> | ||
</> | ||
) | ||
} | ||
|
||
export default Renderer; |