Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jan 2, 2024
1 parent 9363139 commit 76fa616
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 137 deletions.
72 changes: 0 additions & 72 deletions src/app/series/[...slug].tsx

This file was deleted.

44 changes: 44 additions & 0 deletions src/app/series/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// TODO: refactor
import { getSeriesBySeriesName } from '../../../api/series';
import { SeriresWithArticlesResponse, SeriresWithArticles } from '../../../models/series';
import { Article } from '../../../models/article';
import { getRequestContext } from '../../../utils/requestContext';
import { Renderer } from './renderer';

export default async function Page(ctx: any) {
const { props } = await get(ctx);
return <Renderer {...props} />;
}

export async function get(ctx: any) {
const seriesName = ctx.params.slug;
const response: Response = await getSeriesBySeriesName(seriesName, getRequestContext(ctx));
// ctx.res.statusCode = response.status;

let seriresWithArticles: SeriresWithArticles = null;
if (response.status === 200) {
let seriresWithArticlesResponse: SeriresWithArticlesResponse = await response.json() as SeriresWithArticlesResponse;
seriresWithArticles = {
id: seriresWithArticlesResponse.id,
name: seriresWithArticlesResponse.name,
title: seriresWithArticlesResponse.title,
description: seriresWithArticlesResponse.description,
articles: seriresWithArticlesResponse.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,
seriresWithArticles: seriresWithArticles
}
}
}
37 changes: 37 additions & 0 deletions src/app/series/[slug]/renderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// TODO: refactor
import HeadMetaComponent from '../../../components/headmeta';
import CoverWithNavigationComponent from '../../../components/cover/withNavigation';
import SeriesWithArticlesComponent from '../../../components/seriesWithArticles';
import { defaultRobotsMeta } from '../../../../config';
import PlanePage from '../../../components/planePage';

export const Renderer: React.FunctionComponent<{
statusCode,
seriresWithArticles
}> = ({ statusCode, seriresWithArticles }) => {
if (statusCode !== 200) {
return <PlanePage
title={statusCode.toString()}
content="Something went to wrong..."
/>
}
return (
<>
<HeadMetaComponent
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={{
title: seriresWithArticles.title,
tags: null,
publishedAt: null,
}}
/>
<main>
<SeriesWithArticlesComponent
seriresWithArticles={seriresWithArticles}
/>
</main>
</>
)
}
65 changes: 0 additions & 65 deletions src/app/series/index.tsx

This file was deleted.

34 changes: 34 additions & 0 deletions src/app/series/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { getSeries } from '../../api/series';
import { Series, SeriesResponse } from '../../models/series';
import { getRequestContext } from '../../utils/requestContext';
import { Renderer } from './renderer';

export default async function Page(req: any) {
const { props } = await get(req);
return <Renderer {...props} />;
}

export async function get(req: any) {
const response: Response = await getSeries(getRequestContext(req))
// ctx.res.statusCode = response.status;

let series: Array<Series> = [];
if (response.status === 200) {
let seriesResponse: Array<SeriesResponse> = await response.json() as Array<SeriesResponse>;
series = seriesResponse.map(series => {
return {
id: series.id,
name: series.name,
title: series.title,
description: series.description
} as Series
});
}

return {
props: {
statusCode: response.status,
series: series
}
}
}
38 changes: 38 additions & 0 deletions src/app/series/renderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import HeadMetaComponent from '../../components/headmeta';
import CoverWithNavigationComponent from '../../components/cover/withNavigation';
import SeriesComponent from '../../components/series';
import { Series } from '../../models/series';
import { defaultRobotsMeta } from '../../../config';
import PlanePage from '../../components/planePage';

export const Renderer: React.FunctionComponent<{
statusCode: number,
series: Array<Series>
}> = ({ statusCode, series }) => {
if (statusCode !== 200) {
return <PlanePage
title={statusCode.toString()}
content="Something went to wrong..."
/>
}

return (
<>
<HeadMetaComponent
robotsMeta={defaultRobotsMeta}
/>
<CoverWithNavigationComponent
contentCover={{
title: "Series",
tags: null,
publishedAt: null,
}}
/>
<main>
<SeriesComponent
series={series}
/>
</main>
</>
)
}

0 comments on commit 76fa616

Please sign in to comment.