mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
- 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
53 lines
1.5 KiB
TypeScript
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>
|
|
)
|
|
})
|