@@ -3,6 +3,8 @@ const Markdown = lazy(() => import("react-markdown"));
3
3
4
4
import {
5
5
AIIcon ,
6
+ CopyConfirmIcon ,
7
+ CopyIcon ,
6
8
LoadingIcon ,
7
9
ThumbsDownIcon ,
8
10
ThumbsUpIcon ,
@@ -91,6 +93,7 @@ export const Message = ({
91
93
} ) => {
92
94
const { rateChatCompletion } = useChatState ( ) ;
93
95
const [ positive , setPositive ] = React . useState < boolean | null > ( null ) ;
96
+ const [ copied , setCopied ] = React . useState < boolean > ( false ) ;
94
97
const { props } = useModalState ( ) ;
95
98
96
99
const ecommerceItems = message . additional
@@ -115,7 +118,7 @@ export const Message = ({
115
118
. filter (
116
119
( item , index , array ) =>
117
120
array . findIndex ( ( arrayItem ) => arrayItem . title === item . title ) ===
118
- index && item . title ,
121
+ index && item . title ,
119
122
)
120
123
. map ( ( item , index ) => (
121
124
< a
@@ -176,37 +179,49 @@ export const Message = ({
176
179
< div >
177
180
{ message . additional
178
181
? props . type !== "ecommerce" && (
179
- < div className = "additional-links" >
180
- { message . additional
181
- . filter (
182
- ( chunk ) =>
183
- ( chunk . metadata . heading ||
184
- chunk . metadata . title ||
185
- chunk . metadata . page_title ) &&
186
- chunk . link ,
187
- )
188
- . map ( ( chunk ) => [
189
- chunk . metadata . heading ||
182
+ < div className = "additional-links" >
183
+ { message . additional
184
+ . filter (
185
+ ( chunk ) =>
186
+ ( chunk . metadata . heading ||
190
187
chunk . metadata . title ||
191
- chunk . metadata . page_title ,
188
+ chunk . metadata . page_title ) &&
192
189
chunk . link ,
193
- ] )
194
- . filter (
195
- ( link , index , array ) =>
196
- array . findIndex ( ( item ) => item [ 0 ] === link [ 0 ] ) ===
197
- index && link [ 0 ] ,
198
- )
199
- . map ( ( link , index ) => (
200
- < a key = { index } href = { link [ 1 ] as string } target = "_blank" >
201
- { link [ 0 ] }
202
- </ a >
203
- ) ) }
204
- </ div >
205
- )
190
+ )
191
+ . map ( ( chunk ) => [
192
+ chunk . metadata . heading ||
193
+ chunk . metadata . title ||
194
+ chunk . metadata . page_title ,
195
+ chunk . link ,
196
+ ] )
197
+ . filter (
198
+ ( link , index , array ) =>
199
+ array . findIndex ( ( item ) => item [ 0 ] === link [ 0 ] ) ===
200
+ index && link [ 0 ] ,
201
+ )
202
+ . map ( ( link , index ) => (
203
+ < a key = { index } href = { link [ 1 ] as string } target = "_blank" >
204
+ { link [ 0 ] }
205
+ </ a >
206
+ ) ) }
207
+ </ div >
208
+ )
206
209
: null }
207
210
< div className = "feedback-wrapper" >
208
211
< span className = "spacer" > </ span >
209
212
< div className = "feedback-icons" >
213
+ { copied ? < CopyConfirmIcon /> :
214
+ < button
215
+ onClick = { ( ) => {
216
+ void navigator . clipboard . writeText ( message . text ) . then ( ( ) => {
217
+ setCopied ( true ) ;
218
+ setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
219
+ } ) ;
220
+ } }
221
+ >
222
+ < CopyIcon />
223
+ </ button >
224
+ }
210
225
< button
211
226
className = { positive != null && positive ? "icon-darken" : "" }
212
227
onClick = { ( ) => {
0 commit comments