Files
opencode-manager/frontend/src/components/message/UserMessageActionButtons.tsx
T
Chris Scott c4bb104cc0 fix(frontend): reveal transcript actions on focus and bound the shell preview
- expose the user message action buttons to keyboard focus, not just hover
- compute the shell preview tail once per output change and clamp very long lines
2026-10-21 23:14:12 -04:00

53 lines
1.5 KiB
TypeScript

import { memo } from 'react'
import { X, Loader2 } from 'lucide-react'
import { useUndoMessage } from '@/hooks/useUndoMessage'
import { useMobile } from '@/hooks/useMobile'
interface UserMessageActionButtonsProps {
sessionId: string
directory?: string
userMessageId: string
userMessageContent: string
onUndo: (restoredPrompt: string) => void
}
export const UserMessageActionButtons = memo(function UserMessageActionButtons({
sessionId,
directory,
userMessageId,
userMessageContent,
onUndo
}: UserMessageActionButtonsProps) {
const isMobile = useMobile()
const undoMessage = useUndoMessage({
sessionId,
directory,
onSuccess: onUndo
})
const handleUndo = () => {
if (undoMessage.isPending) return
undoMessage.mutate({
messageID: userMessageId,
messageContent: userMessageContent
})
}
return (
<div className={`flex items-center gap-1 ${isMobile ? 'opacity-100' : 'opacity-0 group-hover:opacity-100 group-focus-within:opacity-100'} transition-opacity`}>
<button
onClick={handleUndo}
disabled={undoMessage.isPending}
className="p-1 rounded hover:bg-destructive/20 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
title="Undo this message"
>
{undoMessage.isPending ? (
<Loader2 className="w-3.5 h-3.5 animate-spin" />
) : (
<X className="w-3.5 h-3.5" />
)}
</button>
</div>
)
})