Update app/components/MessageOptions.jsx
Browse files
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 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
</
|
| 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;
|