Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jan 1, 2024
1 parent 9ffb9bf commit 9f5e407
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/app/archives/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { headers } from 'next/headers'

import Renderer from './render';
import Renderer from './renderer';
import { getArchives } from '../../api/archives';
import { Archive, ArchiveResponse } from '../../models/archive';
import { getRequestContext } from '../../utils/requestContext';
Expand Down
File renamed without changes.
70 changes: 0 additions & 70 deletions src/app/index.tsx

This file was deleted.

39 changes: 39 additions & 0 deletions src/app/page.tsx
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
}
}
}
40 changes: 40 additions & 0 deletions src/app/renderer.tsx
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;

0 comments on commit 9f5e407

Please sign in to comment.