Skip to content

Commit

Permalink
ui: support copy message content
Browse files Browse the repository at this point in the history
  • Loading branch information
634750802 committed May 14, 2024
1 parent 93d31dd commit a329a3f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/chat/message-operations.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useMyChatContext } from '@/components/chat/context';
import type { ConversationMessageGroupProps } from '@/components/chat/use-grouped-conversation-messages';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import copy from 'copy-to-clipboard';
import { ClipboardIcon, RefreshCwIcon, ShareIcon, ThumbsDown } from 'lucide-react';
import { ClipboardCheckIcon, ClipboardIcon, RefreshCwIcon, ShareIcon, ThumbsDown } from 'lucide-react';
import { useState } from 'react';

export function MessageOperations ({ group }: { group: ConversationMessageGroupProps }) {
const { handleRegenerate } = useMyChatContext();
const [copied, setCopied] = useState(false);
if (!group.finished) {
return;
}
Expand All @@ -27,13 +30,17 @@ export function MessageOperations ({ group }: { group: ConversationMessageGroupP
<Button size="icon" variant="ghost" className="ml-auto rounded-full w-7 h-7">
<ThumbsDown className="w-4 h-4" />
</Button>
<Button size="icon" variant="ghost" className="rounded-full w-7 h-7">
<ClipboardIcon
className="w-4 h-4"
onClick={() => {
copy(group.assistantMessage.content);
}}
/>
<Button
size="icon"
variant="ghost"
className={cn('rounded-full w-7 h-7 transition-colors', copied && '!text-green-500 hover:bg-green-500/10')}
onClick={() => {
setCopied(copy(group.assistantMessage.content));
}}
>
{copied
? <ClipboardCheckIcon className="w-4 h-4" />
: <ClipboardIcon className="w-4 h-4" />}
</Button>
</div>
);
Expand Down

0 comments on commit a329a3f

Please sign in to comment.