Refactor TTS into FloatingTTSButton component with amber/orange styling (#162)

This commit is contained in:
Chris Scott authored and GitHub committed 2026-03-21 00:06:02 -04:00
1 parent b9b5d50643
commit 2e634b5362
3 files changed
+63 -24

No files matched your search

@@ -0,0 +1,53 @@
import { Volume2, VolumeX, Loader2 } from 'lucide-react'
import { useTTS } from '@/hooks/useTTS'
import { useMobile } from '@/hooks/useMobile'
interface FloatingTTSButtonProps {
content: string
}
export function FloatingTTSButton({ content }: FloatingTTSButtonProps) {
const { speak, stop, isEnabled, isPlaying, isLoading, originalText } = useTTS()
const isMobile = useMobile()
if (!isEnabled || !content.trim()) {
return null
}
const isThisPlaying = (isPlaying || isLoading) && originalText === content
const handleClick = () => {
if (isThisPlaying) {
stop()
} else {
speak(content)
}
}
const buttonPosition = isMobile ? 'bottom-24' : 'bottom-20'
return (
<button
onClick={handleClick}
className={`fixed ${buttonPosition} right-4 z-50 flex items-center gap-2 px-4 py-3 rounded-xl transition-all duration-200 active:scale-95 hover:scale-105 shadow-lg backdrop-blur-md ${
isThisPlaying
? 'bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border border-red-500/60 shadow-red-500/30'
: 'bg-gradient-to-br from-amber-500 to-orange-600 hover:from-amber-400 hover:to-orange-500 text-white border border-amber-400/60 shadow-amber-500/30'
}`}
title={isThisPlaying ? 'Stop playback' : 'Play last response'}
aria-label={isThisPlaying ? 'Stop playback' : 'Play last response'}
disabled={isLoading && originalText !== content}
>
{isLoading && isThisPlaying ? (
<Loader2 className="w-5 h-5 animate-spin" />
) : isThisPlaying ? (
<VolumeX className="w-5 h-5" />
) : (
<Volume2 className="w-5 h-5" />
)}
<span className="text-sm font-medium hidden sm:inline">
{isThisPlaying ? 'Stop' : 'Play Last'}
</span>
</button>
)
}
@@ -1,8 +1,7 @@
import { memo } from 'react'
import type { components } from '@/api/opencode-types'
import { Volume2, Loader2 } from 'lucide-react'
import { Volume2, VolumeX, Loader2 } from 'lucide-react'
import { TextPart } from './TextPart'
import { SquareFill } from '@/components/ui/square-fill'
import { PatchPart } from './PatchPart'
import { ToolCallPart } from './ToolCallPart'
import { RetryPart } from './RetryPart'
@@ -59,14 +58,12 @@ function getCopyableContent(part: Part, allParts?: Part[]): string {
}
}
interface TTSButtonProps {
content: string
className?: string
}
export function TTSButton({ content, className = "" }: TTSButtonProps) {
function TTSButton({ content, className = "" }: TTSButtonProps) {
const { speak, stop, isEnabled, isPlaying, isLoading, originalText } = useTTS()
if (!isEnabled || !content.trim()) {
@@ -93,7 +90,7 @@ export function TTSButton({ content, className = "" }: TTSButtonProps) {
{isLoading && isThisPlaying ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : isThisPlaying ? (
<SquareFill className="w-4 h-4" />
<VolumeX className="w-4 h-4" />
) : (
<Volume2 className="w-4 h-4" />
)}
@@ -101,8 +98,6 @@ export function TTSButton({ content, className = "" }: TTSButtonProps) {
)
}
export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, onChildSessionClick, messageTextContent }: MessagePartProps) {
const copyableContent = getCopyableContent(part, allParts)
const isMobile = useMobile()