Perplexica/ui/components/MessageActions/Copy.tsx

24 lines
972 B
TypeScript
Raw Normal View History

2024-07-05 14:36:50 +08:00
import { Check, ClipboardList } from "lucide-react";
import { Message } from "../ChatWindow";
import { useState } from "react";
2024-04-09 16:21:05 +05:30
2024-07-05 14:36:50 +08:00
const Copy = ({ message, initialMessage }: { message: Message; initialMessage: string }) => {
2024-04-09 16:21:05 +05:30
const [copied, setCopied] = useState(false);
return (
<button
onClick={() => {
const contentToCopy = `${initialMessage}${message.sources && message.sources.length > 0 && `\n\nCitations:\n${message.sources?.map((source: any, i: any) => `[${i + 1}] ${source.metadata.url}`).join(`\n`)}`}`;
navigator.clipboard.writeText(contentToCopy);
setCopied(true);
setTimeout(() => setCopied(false), 1000);
}}
2024-05-27 11:49:09 +08:00
className="p-2 text-black/70 dark:text-white/70 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary transition duration-200 hover:text-black dark:hover:text-white"
2024-04-09 16:21:05 +05:30
>
{copied ? <Check size={18} /> : <ClipboardList size={18} />}
</button>
);
};
export default Copy;