11import  styles  from  "@/styles/components/PromptArea.module.scss" ; 
22import  {  useState ,  useRef ,  useEffect ,  useCallback  }  from  "react" ; 
33import  {  FontAwesomeIcon  }  from  "@fortawesome/react-fontawesome" ; 
4- import  {  merriweather500  }  from  "@/utils/fonts" ; 
4+ import  {  merriweather400 ,   merriweather500  }  from  "@/utils/fonts" ; 
55import  { 
66  faArrowUp , 
77  faPaperclip , 
@@ -12,7 +12,7 @@ type PromptAreaProps = {
1212  isDisabled : boolean ; 
1313  canCancel : boolean ; 
1414  canAttach : boolean ; 
15-   onSend : ( prompt : string )  =>  void ; 
15+   onSend : ( prompt : string ,   promptImages :  string [ ] )  =>  void ; 
1616  onCancel : ( )  =>  void ; 
1717} ; 
1818
@@ -24,16 +24,19 @@ const PromptArea: React.FC<PromptAreaProps> = ({
2424  onCancel, 
2525} )  =>  { 
2626  const  [ prompt ,  setPrompt ]  =  useState ( "" ) ; 
27+   const  [ attachedImages ,  setAttachedImages ]  =  useState < string [ ] > ( [ ] ) ; 
2728  const  textareaRef  =  useRef < HTMLTextAreaElement  |  null > ( null ) ; 
2829
2930  const  handleSend  =  ( )  =>  { 
30-     onSend ( prompt . trim ( ) ) ; 
31+     onSend ( prompt . trim ( ) ,  attachedImages ) ; 
32+     setAttachedImages ( [ ] ) ; 
3133    setPrompt ( "" ) ; 
3234  } ; 
3335
3436  const  handleKeyDown  =  ( e : React . KeyboardEvent < HTMLTextAreaElement > )  =>  { 
3537    if  ( e . key  ===  "Enter"  &&  ! e . shiftKey )  { 
3638      e . preventDefault ( ) ; 
39+ 
3740      if  ( prompt . trim ( ) . length  >  0  &&  ! isDisabled )  { 
3841        handleSend ( ) ; 
3942      } 
@@ -44,6 +47,33 @@ const PromptArea: React.FC<PromptAreaProps> = ({
4447    setPrompt ( e . target . value ) ; 
4548  } ; 
4649
50+   const  handleImageUpload  =  ( e : React . ChangeEvent < HTMLInputElement > )  =>  { 
51+     const  files  =  e . target . files ; 
52+ 
53+     if  ( files )  { 
54+       const  uploadedImages : string [ ]  =  [ ] ; 
55+ 
56+       Array . from ( files ) . forEach ( ( file )  =>  { 
57+         const  reader  =  new  FileReader ( ) ; 
58+         reader . onload  =  ( event )  =>  { 
59+           const  target  =  event . target ; 
60+ 
61+           if  ( target  ===  null )  { 
62+             return ; 
63+           } 
64+ 
65+           uploadedImages . push ( target . result  as  string ) ; 
66+           setAttachedImages ( ( prev )  =>  [ ...prev ,  target . result  as  string ] ) ; 
67+         } ; 
68+ 
69+         reader . readAsDataURL ( file ) ; 
70+       } ) ; 
71+     } 
72+ 
73+     // Reset the file input 
74+     e . target . value  =  "" ; 
75+   } ; 
76+ 
4777  const  adjustTextareaHeight  =  useCallback ( ( )  =>  { 
4878    if  ( textareaRef . current )  { 
4979      textareaRef . current . style . height  =  "auto" ; 
@@ -77,8 +107,22 @@ const PromptArea: React.FC<PromptAreaProps> = ({
77107          spellCheck = { false } 
78108        /> 
79109        < div  className = { styles . buttonContainer } > 
80-           < button  disabled = { isDisabled  ||  ! canAttach } > 
110+           < button  type = "button"  disabled = { isDisabled  ||  ! canAttach } > 
111+             { attachedImages . length  >  0  &&  ( 
112+               < span 
113+                 className = { `${ styles . imageCount } ${ merriweather400 . className }  } 
114+               > 
115+                 { Math . min ( attachedImages . length ,  99 ) } 
116+               </ span > 
117+             ) } 
81118            < FontAwesomeIcon  icon = { faPaperclip }  /> 
119+             < input 
120+               id = "file-upload" 
121+               type = "file" 
122+               multiple 
123+               accept = "image/*" 
124+               onChange = { handleImageUpload } 
125+             /> 
82126          </ button > 
83127          { canCancel  ? ( 
84128            < button  onClick = { onCancel } > 
0 commit comments