Niansuh commited on
Commit
2c41b79
·
verified ·
1 Parent(s): a3845cd

Update app/components/MessageOptions.jsx

Browse files
Files changed (1) hide show
  1. app/components/MessageOptions.jsx +29 -29
app/components/MessageOptions.jsx CHANGED
@@ -1,29 +1,29 @@
1
- "use client";
2
- import { useState } from 'react';
3
- import { MdOutlineDone } from "react-icons/md";
4
- import { MdContentCopy } from 'react-icons/md';
5
- import { GrPowerReset } from 'react-icons/gr';
6
-
7
- const MessageOptions = ({ message, regenerateMessage }) => {
8
- const [icon, setIcon] = useState(<MdContentCopy />);
9
-
10
- const handleCopy = () => {
11
- navigator.clipboard.writeText(message.content);
12
- setIcon(<MdOutlineDone />);
13
-
14
- setTimeout(() => {
15
- setIcon(<MdContentCopy />);
16
- }, 1000);
17
- };
18
-
19
- return (
20
- (
21
- <div className="message-options">
22
- <button onClick={handleCopy}>{icon}</button>
23
- <button onClick={() => regenerateMessage(message)}><GrPowerReset /></button>
24
- </div>
25
- )
26
- );
27
- };
28
-
29
- export default MessageOptions;
 
1
+ "use client";
2
+ import { useState } from 'react';
3
+ import { MdOutlineDone } from "react-icons/md";
4
+ import { MdContentCopy } from 'react-icons/md';
5
+ import { GrPowerReset } from 'react-icons/gr';
6
+
7
+ const MessageOptions = ({ message, regenerateMessage }) => {
8
+ const [icon, setIcon] = useState(<MdContentCopy />);
9
+
10
+ const handleCopy = () => {
11
+ if (message.role === 'bot') { // Check if the message is from the bot
12
+ navigator.clipboard.writeText(message.content);
13
+ setIcon(<MdOutlineDone />);
14
+
15
+ setTimeout(() => {
16
+ setIcon(<MdContentCopy />);
17
+ }, 1000);
18
+ }
19
+ };
20
+
21
+ return (
22
+ <div className="message-options">
23
+ <button onClick={handleCopy}>{icon}</button>
24
+ <button onClick={() => regenerateMessage(message)}><GrPowerReset /></button>
25
+ </div>
26
+ );
27
+ };
28
+
29
+ export default MessageOptions;