Skip to content

Commit

Permalink
fix(speech): pause audio when navigation to another page
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonGolms committed Mar 8, 2021
1 parent 92c771a commit e63244d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/SpeechFabButton/SpeechFabButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IonFab, IonFabButton } from '@ionic/react';
import React from 'react';
import { useParams } from 'react-router';
import { useEffect } from 'react';
import { useLocation, useParams } from 'react-router';
import { ChapterId } from '../Chapters';
import { formatSecondsToTimeMinutes } from '../../utils/format';
import { useSpeechAudio } from './hooks/useSpeechAudio';
Expand All @@ -12,12 +12,21 @@ interface RouteChapterProps {
}

export const SpeechFabButton = () => {
const location = useLocation();
const { chapterId, sectionId } = useParams<RouteChapterProps>();
const { isLoading, isPlaying, pause, play, restTime } = useSpeechAudio(
chapterId,
sectionId,
);

// NOTE: pause audio when navigating to another page
useEffect(() => {
return () => {
pause();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location]);

return (
<IonFab vertical="top" horizontal="end" edge slot="fixed">
<IonFabButton
Expand Down

0 comments on commit e63244d

Please sign in to comment.