fix(MoodMusic): resolve exhaustive-deps so CI build passes; behaviour unchanged
Some checks are pending
CI / build-and-test (push) Waiting to run
Some checks are pending
CI / build-and-test (push) Waiting to run
This commit is contained in:
@@ -40,12 +40,11 @@ export default function MoodMusic() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Create audio element on mount
|
||||
// Create audio element on mount (volume handled by separate effect)
|
||||
useEffect(() => {
|
||||
const audio = new Audio();
|
||||
audio.preload = 'auto';
|
||||
audio.loop = true;
|
||||
audio.volume = volume;
|
||||
audioRef.current = audio;
|
||||
return () => {
|
||||
if (fadeTimeoutRef.current) clearTimeout(fadeTimeoutRef.current);
|
||||
@@ -54,13 +53,22 @@ export default function MoodMusic() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Update volume when it changes
|
||||
// Set initial volume on mount, then update whenever volume changes
|
||||
useEffect(() => {
|
||||
if (audioRef.current) {
|
||||
audioRef.current.volume = volume;
|
||||
}
|
||||
}, [volume]);
|
||||
|
||||
const stopPlayback = useCallback(() => {
|
||||
if (audioRef.current) {
|
||||
audioRef.current.pause();
|
||||
audioRef.current.src = '';
|
||||
}
|
||||
setActiveMood(null);
|
||||
setNowPlaying('');
|
||||
}, []);
|
||||
|
||||
const playMood = useCallback((track) => {
|
||||
if (!track || !audioRef.current) return;
|
||||
|
||||
@@ -111,16 +119,7 @@ export default function MoodMusic() {
|
||||
setActiveMood(track.mood);
|
||||
setNowPlaying(track.title);
|
||||
}
|
||||
}, [activeMood, volume]);
|
||||
|
||||
const stopPlayback = useCallback(() => {
|
||||
if (audioRef.current) {
|
||||
audioRef.current.pause();
|
||||
audioRef.current.src = '';
|
||||
}
|
||||
setActiveMood(null);
|
||||
setNowPlaying('');
|
||||
}, []);
|
||||
}, [activeMood, volume, stopPlayback]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user