nexus/ui/src/components/ChatMessageActions.tsx
Nexus Dev 6551e7e1b7 feat(24-03): add bookmark toggle to ChatMessage and ChatMessageActions
- Add onBookmark/isBookmarked props to ChatMessageActions
- Render ChatMessageBookmark as last action for user and assistant messages
- Add onBookmark/isBookmarked props to ChatMessage, thread to ChatMessageActions
- System messages do not receive bookmark actions
2026-04-04 03:55:48 +00:00

83 lines
2.4 KiB
TypeScript

import { Pencil, RefreshCw } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { ChatMessageBookmark } from "./ChatMessageBookmark";
interface ChatMessageActionsProps {
role: "user" | "assistant" | "system";
isStreaming?: boolean;
onEdit?: () => void;
onRetry?: () => void;
onBookmark?: () => void;
isBookmarked?: boolean;
}
export function ChatMessageActions({ role, isStreaming, onEdit, onRetry, onBookmark, isBookmarked }: ChatMessageActionsProps) {
if (isStreaming) return null;
if (role === "user" && onEdit) {
return (
<div className="absolute top-1 right-1 hidden group-hover:flex items-center gap-0.5">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-6 w-6"
onClick={onEdit}
aria-label="Edit message"
>
<Pencil className="h-3.5 w-3.5" />
</Button>
</TooltipTrigger>
<TooltipContent>Edit message</TooltipContent>
</Tooltip>
{onBookmark && (
<ChatMessageBookmark
messageId=""
conversationId=""
isBookmarked={isBookmarked ?? false}
onToggle={onBookmark}
/>
)}
</div>
);
}
if (role === "assistant") {
const hasActions = !!onRetry || !!onBookmark;
if (!hasActions) return null;
return (
<div className="flex justify-end mt-1 gap-0.5">
{onRetry && (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-6 w-6 hidden group-hover:inline-flex"
onClick={onRetry}
aria-label="Retry response"
>
<RefreshCw className="h-3.5 w-3.5" />
</Button>
</TooltipTrigger>
<TooltipContent>Retry response</TooltipContent>
</Tooltip>
)}
{onBookmark && (
<div className="hidden group-hover:inline-flex">
<ChatMessageBookmark
messageId=""
conversationId=""
isBookmarked={isBookmarked ?? false}
onToggle={onBookmark}
/>
</div>
)}
</div>
);
}
return null;
}