Skip to content

Commit 12dbbad

Browse files
committed
言語名の取得を修正
1 parent 0aaf2d6 commit 12dbbad

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/[docs_id]/chatForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { askAI } from "@/app/actions/chatActions";
55
import { StyledMarkdown } from "./markdown";
66
import useSWR from "swr";
77
import { getQuestionExample } from "../actions/questionExample";
8+
import { getLanguageName } from "../pagesList";
89

910
export function ChatForm({
1011
docs_id,
@@ -18,7 +19,7 @@ export function ChatForm({
1819
const [isLoading, setIsLoading] = useState(false);
1920
const [isFormVisible, setIsFormVisible] = useState(false);
2021

21-
const lang = docs_id.split("-")[0];
22+
const lang = getLanguageName(docs_id);
2223
const { data: exampleData, error: exampleError } = useSWR(
2324
// 質問フォームを開いたときだけで良い
2425
isFormVisible ? { lang, documentContent } : null,

app/pagesList.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ export const pagesList = [
3030
],
3131
},
3232
] as const;
33+
34+
// ${lang_id}-${page_id} から言語名を取得
35+
export function getLanguageName(docs_id: string){
36+
const lang_id = docs_id.split("-")[0];
37+
const lang = pagesList.find((lang) => lang.id === lang_id)?.lang;
38+
if(!lang){
39+
throw new Error(`Unknown language id: ${lang_id}`);
40+
}
41+
return lang;
42+
}

0 commit comments

Comments
 (0)