1
- import React , { useState , useRef , useEffect , useCallback } from 'react' ;
1
+ import {
2
+ FC ,
3
+ useState ,
4
+ ChangeEvent ,
5
+ KeyboardEvent ,
6
+ useRef ,
7
+ useEffect ,
8
+ useCallback ,
9
+ useMemo ,
10
+ } from 'react' ;
2
11
import { Textarea } from '@fluentui/react-components' ;
3
- import { useClasses } from './ComposeBox.styles' ;
4
- import NewMessageToolbar from './ComposeBoxToolbar/ComposeBoxToolbar' ;
5
- import { useCardStore } from '../../stores/CardStore' ;
6
- import AttachmentsContainer from '../AttachmentsContainer/AttachmentsContainer' ;
7
12
import { Attachment } from '@microsoft/spark.api' ;
13
+
14
+ import { useCardStore } from '../../stores/CardStore' ;
8
15
import { AttachmentType } from '../../types/Attachment' ;
16
+ import AttachmentsContainer from '../AttachmentsContainer/AttachmentsContainer' ;
17
+ import NewMessageToolbar from './ComposeBoxToolbar/ComposeBoxToolbar' ;
18
+ import useComposeBoxClasses from './ComposeBox.styles' ;
9
19
10
20
export interface ComposeBoxProps {
11
21
onSend : ( message : string , attachments ?: Attachment [ ] ) => void ;
12
22
messageHistory : string [ ] ;
13
23
onMessageSent : ( message : string ) => void ;
14
24
}
15
25
16
- const ComposeBox : React . FC < ComposeBoxProps > = ( { onSend, messageHistory, onMessageSent } ) => {
17
- const classes = useClasses ( ) ;
26
+ const ComposeBox : FC < ComposeBoxProps > = ( { onSend, messageHistory, onMessageSent } ) => {
27
+ const classes = useComposeBoxClasses ( ) ;
18
28
const [ message , setMessage ] = useState ( '' ) ;
19
29
const [ attachments , setAttachments ] = useState < Attachment [ ] > ( [ ] ) ;
20
30
const [ uiAttachments , setUiAttachments ] = useState < AttachmentType [ ] > ( [ ] ) ;
@@ -31,7 +41,7 @@ const ComposeBox: React.FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessa
31
41
32
42
// Convert API Attachment to UI AttachmentType
33
43
const convertToAttachmentType = ( attachment : Attachment ) : AttachmentType => {
34
- // Check if it's a card attachment
44
+ // Check for card attachment
35
45
if ( attachment . contentType ?. startsWith ( 'application/vnd.microsoft.card.' ) ) {
36
46
return {
37
47
type : 'card' ,
@@ -95,7 +105,7 @@ const ComposeBox: React.FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessa
95
105
} , [ message , attachments , onSend , onMessageSent ] ) ;
96
106
97
107
const handleKeyDown = useCallback (
98
- ( e : React . KeyboardEvent ) => {
108
+ ( e : KeyboardEvent ) => {
99
109
if ( e . key === 'Enter' && ! e . shiftKey ) {
100
110
e . preventDefault ( ) ;
101
111
handleSendMessage ( ) ;
@@ -166,14 +176,14 @@ const ComposeBox: React.FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessa
166
176
) ;
167
177
168
178
// Memoized message input handler to prevent re-renders
169
- const handleMessageChange = useCallback ( ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
179
+ const handleMessageChange = useCallback ( ( e : ChangeEvent < HTMLTextAreaElement > ) => {
170
180
setMessage ( e . target . value ) ;
171
181
} , [ ] ) ;
172
182
173
183
// Check if there's content to send
174
184
const hasContent = message . trim ( ) . length > 0 || attachments . length > 0 ;
175
185
176
- const memoizedToolbar = React . useMemo (
186
+ const memoizedToolbar = useMemo (
177
187
( ) => < NewMessageToolbar onSend = { handleToolbarAction } hasContent = { hasContent } /> ,
178
188
[ handleToolbarAction , hasContent ]
179
189
) ;
0 commit comments