33import { useState , FormEvent } from "react" ;
44import { askAI } from "@/app/actions/chatActions" ;
55
6- export function ChatForm ( ) {
6+ export function ChatForm ( { documentContent } : { documentContent : string } ) {
77 const [ inputValue , setInputValue ] = useState ( "" ) ;
88 const [ response , setResponse ] = useState ( "" ) ;
99 const [ isLoading , setIsLoading ] = useState ( false ) ;
@@ -16,83 +16,84 @@ export function ChatForm() {
1616
1717 const formData = new FormData ( ) ;
1818 formData . append ( "message" , inputValue ) ;
19+ formData . append ( "documentContent" , documentContent ) ;
1920
2021 const result = await askAI ( { response : "" , error : null } , formData ) ;
2122
2223 if ( result . error ) {
2324 setResponse ( `エラー: ${ result . error } ` ) ;
24- } else {
25+ } else {
2526 setResponse ( result . response ) ;
2627 }
27-
28+
2829 setIsLoading ( false ) ;
2930 } ;
3031 return (
3132 < >
3233 { isFormVisible && (
3334 < form className = "border border-2 border-primary shadow-xl p-6 rounded-lg bg-base-100" style = { { width :"100%" , textAlign :"center" , boxShadow :"-moz-initial" } } onSubmit = { handleSubmit } >
34- < h2 className = "text-xl font-bold mb-4 text-left relative -top-2 font-mono h-2" >
35- AIへ質問
36- </ h2 >
35+ < h2 className = "text-xl font-bold mb-4 text-left relative -top-2 font-mono h-2" >
36+ AIへ質問
37+ </ h2 >
3738 < div className = "input-area" style = { { height :"80px" } } >
38- < textarea
39- className = "textarea textarea-white textarea-md"
40- placeholder = "質問を入力してください"
39+ < textarea
40+ className = "textarea textarea-white textarea-md"
41+ placeholder = "質問を入力してください"
4142 style = { { width : "100%" , height : "110px" , resize : "none" } }
42- value = { inputValue }
43- onChange = { ( e ) => setInputValue ( e . target . value ) }
44- disabled = { isLoading }
45- > </ textarea >
46- </ div >
47- < br />
43+ value = { inputValue }
44+ onChange = { ( e ) => setInputValue ( e . target . value ) }
45+ disabled = { isLoading }
46+ > </ textarea >
47+ </ div >
48+ < br />
4849 < div className = "controls" style = { { position :"relative" , top :"22px" , display :"flex" , alignItems :"center" , justifyContent :"space-between" } } >
49- < div className = "left-icons" >
50- < button
51- className = "btn btn-soft btn-secondary rounded-full"
52- onClick = { ( ) => setIsFormVisible ( false ) }
53- >
50+ < div className = "left-icons" >
51+ < button
52+ className = "btn btn-soft btn-secondary rounded-full"
53+ onClick = { ( ) => setIsFormVisible ( false ) }
54+ >
5455
55- 閉じる
56- </ button >
57- </ div >
58- < div className = "right-controls" >
59- < button
60- type = "submit"
61- className = "btn btn-soft btn-circle btn-primary rounded-full"
62- title = "送信"
56+ 閉じる
57+ </ button >
58+ </ div >
59+ < div className = "right-controls" >
60+ < button
61+ type = "submit"
62+ className = "btn btn-soft btn-circle btn-primary rounded-full"
63+ title = "送信"
6364 style = { { marginTop :"10px" } }
64- disabled = { isLoading }
65- >
66- < span className = "icon" > ➤</ span >
67- </ button >
65+ disabled = { isLoading }
66+ >
67+ < span className = "icon" > ➤</ span >
68+ </ button >
69+ </ div >
6870 </ div >
69- </ div >
70- </ form >
71+ </ form >
7172 ) }
7273 { ! isFormVisible && (
73- < button
74- className = "btn btn-soft btn-secondary rounded-full"
75- onClick = { ( ) => setIsFormVisible ( true ) }
76- >
77- チャットを開く
78- </ button >
74+ < button
75+ className = "btn btn-soft btn-secondary rounded-full"
76+ onClick = { ( ) => setIsFormVisible ( true ) }
77+ >
78+ チャットを開く
79+ </ button >
7980 ) }
8081
8182 { response && (
8283 < article >
8384 < h3 className = "text-lg font-semibold mb-2" > AIの回答</ h3 >
8485 < div className = "chat chat-start" >
8586 < div className = "chat-bubble chat-bubble-primary" >
86- < div className = "response-container" > { response } </ div >
87+ < div className = "response-container" > { response } </ div >
8788 </ div >
8889 </ div >
8990 </ article >
9091 ) }
9192
9293 { isLoading && (
93- < div className = "mt-2 text-l text-gray-500 animate-pulse" >
94- AIが考え中です…
95- </ div >
94+ < div className = "mt-2 text-l text-gray-500 animate-pulse" >
95+ AIが考え中です…
96+ </ div >
9697 ) }
9798
9899 </ >
0 commit comments