-
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
9363139
commit 76fa616
Showing
6 changed files
with
153 additions
and
137 deletions.
There are no files selected for viewing
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,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 | ||
} | ||
} | ||
} |
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,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> | ||
</> | ||
) | ||
} |
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,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 | ||
} | ||
} | ||
} |
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,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> | ||
</> | ||
) | ||
} |