diff --git a/app/[docs_id]/chatForm.tsx b/app/[docs_id]/chatForm.tsx index d2ad7f7..932be11 100644 --- a/app/[docs_id]/chatForm.tsx +++ b/app/[docs_id]/chatForm.tsx @@ -28,6 +28,7 @@ export function ChatForm({ // const [messages, updateChatHistory] = useChatHistory(sectionId); const [inputValue, setInputValue] = useState(""); const [isLoading, setIsLoading] = useState(false); + const [errorMessage, setErrorMessage] = useState(null); const { addChat } = useChatHistoryContext(); @@ -68,6 +69,7 @@ export function ChatForm({ const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setIsLoading(true); + setErrorMessage(null); // Clear previous error message const userMessage: ChatMessage = { sender: "user", text: inputValue }; @@ -89,12 +91,8 @@ export function ChatForm({ }); if (result.error) { - const errorMessage: ChatMessage = { - sender: "error", - text: `エラー: ${result.error}`, - }; + setErrorMessage(result.error); console.log(result.error); - // TODO: ユーザーに表示 } else { const aiMessage: ChatMessage = { sender: "ai", text: result.response }; const chatId = addChat(result.targetSectionId, [userMessage, aiMessage]); @@ -115,28 +113,25 @@ export function ChatForm({ }} onSubmit={handleSubmit} > -
- -
+
-
- -
-
- + {errorMessage && ( +
- - -
+ {errorMessage} +
+ )} +
);