Skip to content

Commit

Permalink
#38 ねこのIDからねこの名前を取り出す関数を実装
Browse files Browse the repository at this point in the history
  • Loading branch information
keitakn committed Jul 2, 2023
1 parent 24fc534 commit 8b835f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/app/chat/[catId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CatId } from '@/features';
import { extractCatNameById, type CatId } from '@/features';
import type { Metadata, ResolvingMetadata } from 'next';
import { Noto_Sans_JP } from 'next/font/google';
import type { JSX, ReactNode } from 'react';
Expand All @@ -21,8 +21,10 @@ export const generateMetadata = async (
parent: ResolvingMetadata
): Promise<Metadata> => {
return {
title: 'AI Cat もこちゃん🐱',
description: 'ねこのAI(もこちゃん)とお話しよう🐱',
title: `AI Cat ${extractCatNameById(params.catId)}ちゃん🐱`,
description: `ねこのAI(${extractCatNameById(
params.catId
)})とお話しよう🐱`,
};
};

Expand Down
19 changes: 18 additions & 1 deletion src/features/cat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export type CatId = 'moko';
import { ExhaustiveError } from '@/utils';

const catIds = ['moko'] as const;

export type CatId = (typeof catIds)[number];

const catNames = ['もこ'] as const;

type CatName = (typeof catNames)[number];

export type FetchCatMessageDto = {
catId: CatId;
Expand All @@ -13,3 +21,12 @@ export type FetchCatMessageResponse = {
export type FetchCatMessage = (
dto: FetchCatMessageDto
) => Promise<FetchCatMessageResponse>;

export const extractCatNameById = (catId: CatId): CatName => {
switch (catId) {
case 'moko':
return 'もこ';
default:
throw new ExhaustiveError(catId);
}
};
2 changes: 2 additions & 0 deletions src/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export type {
FetchCatMessageResponse,
FetchCatMessage,
} from './cat';

export { extractCatNameById } from './cat';

0 comments on commit 8b835f8

Please sign in to comment.