Skip to content

Commit

Permalink
Merge pull request #2400 from aliraza556/Listen-Button-Stuck-Pause-State
Browse files Browse the repository at this point in the history
Fixed[AI Search]:  `Listen` Button Stuck in Pause State After Content is Read Aloud
  • Loading branch information
Rassl authored Nov 8, 2024
2 parents e0dbac2 + 0d79d55 commit a898ce5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/App/SideBar/AiSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const AiSummary = ({ question, response, refId }: Props) => {
const { setAiSummaryAnswer } = useAiSummaryStore((s) => s)
const audioRef = useRef<HTMLAudioElement | null>(null)
const { currentPlayingAudio, setCurrentPlayingAudio } = useAppStore((s) => s)
const [isPlaying, setIsPlaying] = useState(false)

useEffect(() => {
if (ref.current) {
Expand All @@ -60,6 +61,7 @@ export const AiSummary = ({ question, response, refId }: Props) => {

const onAudioPlaybackComplete = () => {
setCurrentPlayingAudio(null)
setIsPlaying(false)
}

if (audioElement) {
Expand All @@ -71,7 +73,7 @@ export const AiSummary = ({ question, response, refId }: Props) => {
audioElement.removeEventListener('ended', onAudioPlaybackComplete)
}
}
}, [setCurrentPlayingAudio])
}, [setCurrentPlayingAudio, isPlaying])

const toggleCollapse = () => {
setCollapsed(!collapsed)
Expand All @@ -88,9 +90,11 @@ export const AiSummary = ({ question, response, refId }: Props) => {
if (audioRef.current.paused) {
audioRef.current.play()
setCurrentPlayingAudio(audioRef)
setIsPlaying(true)
} else {
audioRef.current.pause()
setCurrentPlayingAudio(null)
setIsPlaying(false)
}
}
}
Expand Down

0 comments on commit a898ce5

Please sign in to comment.