Files
Hayden Bleasel 101ca62c2d Update docs styles (#22)
* Initial implementation

* Bump deps

* Update code-block.tsx

* Update navbar.tsx

* Move video to Geistdocs

* Update layout.tsx

* Margin fixes

* Update code-block-tabs.tsx

* Update docs-page.tsx

* Update navbar.tsx

* Add feed

* Update docs-layout.tsx

* Update mobile-menu.tsx

* Fix adaptable layout

* Update docs-page.tsx

* Update docs page composability

* Update global.css

* Remove unused AI Elements

* Update Feedback
2025-11-14 11:56:29 -08:00

57 lines
1.5 KiB
TypeScript

import type { UIMessage } from "ai";
import { CheckIcon, CopyIcon } from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
export const CopyChat = ({ messages }: { messages: UIMessage[] }) => {
const [copied, setCopied] = useState(false);
const handleCopyChat = async () => {
const markdown = messages
.map((message) => {
const role = message.role === "user" ? "You" : "AI";
const content = message.parts
.filter((part) => part.type === "text")
.map((part) => part.text)
.join("\n");
return `**${role}:**\n${content}`;
})
.join("\n\n---\n\n");
try {
await navigator.clipboard.writeText(markdown);
toast.success("Chat copied to clipboard");
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (error) {
toast.error("Failed to copy chat", {
description: error instanceof Error ? error.message : "Unknown error",
});
}
};
const Icon = copied ? CheckIcon : CopyIcon;
return (
<Tooltip>
<TooltipTrigger asChild>
<Button
disabled={messages.length === 0}
onClick={handleCopyChat}
size="icon-sm"
variant="ghost"
>
<Icon className="size-3.5" />
</Button>
</TooltipTrigger>
<TooltipContent>Copy chat</TooltipContent>
</Tooltip>
);
};