@@ -78,8 +78,33 @@ const ChatInput = forwardRef((_props, _ref) => {
78
78
. find ( ( m ) => m ?. from === 'human' && m ?. value !== IMAGE_PLACEHOLDER )
79
79
?. value || '' ;
80
80
81
+ const [ isSharing , setIsSharing ] = React . useState ( false ) ;
82
+ const isSharePending = React . useRef ( false ) ;
83
+ const shareTimeoutRef = React . useRef < NodeJS . Timeout > ( ) ;
84
+ const SHARE_TIMEOUT = 100000 ;
85
+
81
86
const handleShare = async ( ) => {
87
+ if ( isSharePending . current ) {
88
+ return ;
89
+ }
90
+
82
91
try {
92
+ setIsSharing ( true ) ;
93
+ isSharePending . current = true ;
94
+
95
+ shareTimeoutRef . current = setTimeout ( ( ) => {
96
+ setIsSharing ( false ) ;
97
+ isSharePending . current = false ;
98
+ toast ( {
99
+ title : 'Share timeout' ,
100
+ description : 'Please try again later' ,
101
+ status : 'error' ,
102
+ position : 'top' ,
103
+ duration : 3000 ,
104
+ isClosable : true ,
105
+ } ) ;
106
+ } , SHARE_TIMEOUT ) ;
107
+
83
108
const response = await fetch ( reportHTMLUrl ) ;
84
109
const html = await response . text ( ) ;
85
110
@@ -143,6 +168,12 @@ const ChatInput = forwardRef((_props, _ref) => {
143
168
duration : 3000 ,
144
169
isClosable : true ,
145
170
} ) ;
171
+ } finally {
172
+ if ( shareTimeoutRef . current ) {
173
+ clearTimeout ( shareTimeoutRef . current ) ;
174
+ }
175
+ setIsSharing ( false ) ;
176
+ isSharePending . current = false ;
146
177
}
147
178
} ;
148
179
@@ -215,8 +246,9 @@ const ChatInput = forwardRef((_props, _ref) => {
215
246
variant = "tars-ghost"
216
247
aria-label = "Share"
217
248
onClick = { handleShare }
249
+ isDisabled = { isSharing }
218
250
>
219
- < LuScreenShare />
251
+ { isSharing ? < Spinner size = "sm" /> : < LuScreenShare /> }
220
252
</ Button >
221
253
) }
222
254
< div />
0 commit comments