Skip to content

Commit

Permalink
Fix: remember previous range selection (quran#2239)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slo1k committed Nov 19, 2024
1 parent 5bb0edd commit 05aff34
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/AudioPlayer/RepeatAudioModal/RepeatAudioModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getChapterFirstAndLastVerseKey,
getChapterNumberFromKey,
getVerseNumberFromKey,
makeVerseKey,
} from '@/utils/verse';
import { AudioPlayerMachineContext } from 'src/xstate/AudioPlayerMachineContext';
import PreferenceGroup from 'types/auth/PreferenceGroup';
Expand Down Expand Up @@ -90,14 +91,18 @@ const RepeatAudioModal = ({
delayMultiplier: repeatSettings?.delayMultiplier ?? 1,
});

// reset verseRepetition's `to` and `from`, when chapter changed
// Set the default verse repetition range based on the previously selected verses
useEffect(() => {
setVerseRepetition((prevVerseRepetition) => ({
...prevVerseRepetition,
from: selectedVerseKey || firstVerseKeyInThisChapter,
to: selectedVerseKey || lastVerseKeyInThisChapter,
from: repeatSettings?.fromVerseNumber
? makeVerseKey(chapterId, repeatSettings?.fromVerseNumber)
: firstVerseKeyInThisChapter,
to: repeatSettings?.toVerseNumber
? makeVerseKey(chapterId, repeatSettings?.toVerseNumber)
: lastVerseKeyInThisChapter,
}));
}, [chapterId, firstVerseKeyInThisChapter, lastVerseKeyInThisChapter, selectedVerseKey]);
}, [chapterId, firstVerseKeyInThisChapter, lastVerseKeyInThisChapter, repeatSettings]);

const play = () => {
audioService.send({
Expand Down

0 comments on commit 05aff34

Please sign in to comment.