mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(schedules): add read aloud playback to scheduled run reports
This commit is contained in:
1 parent
03500affe8
commit
092add1eb1
5 files changed
+107
-43
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { Loader2, Volume2, VolumeX } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useTTS } from '@/hooks/useTTS'
|
||||
|
||||
interface TTSButtonProps {
|
||||
messageId: string
|
||||
content: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
export function TTSButton({ messageId, content, className }: TTSButtonProps) {
|
||||
const { speakMessage, stop, isEnabled, isPlaying, isLoading, activeMessageId } = useTTS()
|
||||
|
||||
if (!isEnabled || !content.trim()) {
|
||||
return null
|
||||
}
|
||||
|
||||
const isThisPlaying = (isPlaying || isLoading) && activeMessageId === messageId
|
||||
const label = isThisPlaying ? 'Stop playback' : 'Read aloud'
|
||||
|
||||
const handleClick = () => {
|
||||
if (isThisPlaying) {
|
||||
stop()
|
||||
} else {
|
||||
speakMessage(messageId, content)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClick}
|
||||
className={cn('p-1.5 rounded', isThisPlaying ? 'bg-destructive/20 text-destructive hover:bg-destructive/30' : 'bg-card hover:bg-card-hover text-muted-foreground hover:text-foreground', className)}
|
||||
title={label}
|
||||
aria-label={label}
|
||||
disabled={isLoading && !isThisPlaying}
|
||||
>
|
||||
{isLoading && isThisPlaying ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : isThisPlaying ? (
|
||||
<VolumeX className="w-4 h-4" />
|
||||
) : (
|
||||
<Volume2 className="w-4 h-4" />
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user