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 76fa616 commit ac151f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
26 changes: 26 additions & 0 deletions src/app/tags/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Tag } from '../../models/tag';
import { getTags } from '../../api/tags';
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 response: Response = await getTags(getRequestContext(ctx));
// ctx.res.statusCode = response.status;

let tags: Array<Tag> = [];
if (response.status === 200) {
tags = await response.json() as Array<Tag>;
}

return {
props: {
statusCode: response.status,
tags: tags
}
}
}
27 changes: 6 additions & 21 deletions src/app/tags/index.tsx → src/app/tags/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use client';

import HeadMetaComponent from '../../components/headmeta';
import CoverWithNavigationComponent from '../../components/cover/withNavigation';
import TagsComponent from '../../components/tags';
import { Tag } from '../../models/tag';
import { defaultRobotsMeta } from '../../../config';
import { getTags } from '../../api/tags';
import { getRequestContext } from '../../utils/requestContext';
import PlanePage from '../../components/planePage';

export default function Page({ statusCode, tags }) {
export const Renderer: React.FunctionComponent<{
statusCode,
tags
}> = ({ statusCode, tags }) => {
if (statusCode !== 200) {
return <PlanePage
title={statusCode.toString()}
Expand Down Expand Up @@ -35,20 +37,3 @@ export default function Page({ statusCode, tags }) {
</>
)
}

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

let tags: Array<Tag> = [];
if (response.status === 200) {
tags = await response.json() as Array<Tag>;
}

return {
props: {
statusCode: response.status,
tags: tags
}
}
}

0 comments on commit ac151f4

Please sign in to comment.