11import React , { useState } from "react" ;
22import { useChat } from "../context/ChatContext" ;
3+ import { postQuery } from "../api/getQuery" ;
34
45export const UserInput = ( ) => {
56 const [ userInput , setUserInput ] = useState ( "" ) ;
@@ -17,23 +18,41 @@ export const UserInput = () => {
1718 const category = [ "한식" , "일식" , "중식" , "양식" ] ;
1819
1920 const handleSubmit = async ( ) => {
21+ if ( ! optionCheck ) {
22+ const noCategoryMessage = {
23+ type : "text" ,
24+ content : "🚨 카테고리를 선택해주세요." ,
25+ } ;
26+ setMessages ( ( prev ) => [ ...prev , noCategoryMessage ] ) ;
27+ setAllMessages ( ( prev ) => [ ...prev , noCategoryMessage ] ) ;
28+ return ;
29+ }
30+
2031 if ( userInput . trim ( ) !== "" && ! isAiResponding ) {
2132 setMessages ( ( prevMessages ) => [ ...prevMessages , userInput ] ) ;
2233 setAllMessages ( ( prevMessages ) => [ ...prevMessages , userInput ] ) ;
2334 setCallResponse ( true ) ;
2435 setUserInput ( "" ) ;
36+
37+ try {
38+ const response = await postQuery ( userInput , optionCheck ) ;
39+ console . log ( response ) ;
40+ } catch ( err ) {
41+ console . log ( err ) ;
42+ }
2543 }
2644 } ;
2745
28- const handleKeyDown = ( e ) => {
46+ const handleKeyUp = ( e ) => {
2947 if ( e . key === "Enter" ) {
3048 e . preventDefault ( ) ;
3149 handleSubmit ( ) ;
3250 }
3351 } ;
3452
3553 return (
36- < div className = "bg-white p-6 rounded-lg shadow-md" >
54+ < div className = "bg-white p-6 relative rounded-b-xl border-b border-l border-r border-stone-300" >
55+ < div className = "font-semibold mb-2 text-lime-950" > 카테고리(필수)</ div >
3756 < div className = "flex space-x-4 mb-4" >
3857 { category . map ( ( category , idx ) => (
3958 < label key = { idx } className = "flex items-center space-x-2" >
@@ -47,18 +66,17 @@ export const UserInput = () => {
4766 </ label >
4867 ) ) }
4968 </ div >
50-
5169 < div className = "relative flex items-center" >
5270 < input
5371 type = "text"
5472 placeholder = "만들고 싶은 요리를 입력해주세요"
5573 className = "input input-xl w-full pr-28 p-3 border border-gray-300 rounded-lg focus:outline-none"
5674 value = { userInput }
5775 onChange = { handleInputChange }
58- onKeyUp = { handleKeyDown }
76+ onKeyUp = { handleKeyUp }
5977 />
6078 < button
61- className = "btn absolute right-9 top-1/2 transform -translate-y-1/2"
79+ className = "btn absolute right-5 top-1/2 transform -translate-y-1/2"
6280 onClick = { handleSubmit }
6381 disabled = { isAiResponding }
6482 >
0 commit comments