Skip to content

Commit

Permalink
fix: linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Inverseit committed Dec 6, 2023
1 parent 850f813 commit 22a62b2
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/components/header/random-controller/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,39 @@ export function RandomModeButton() {

// Apply Volumes with Timeouts
function applyVolumeChanges(stepDuration) {
clearAllTimeouts(); // Clears existing timeouts

soundsRef.current.filter(sound => sound.active).forEach(initialSound => {
const targetVolume = Math.random();
const volumeSteps = calculateVolumeSteps(initialSound.volume, targetVolume, NUM_STEPS);
clearAllTimeouts() // Clears existing timeouts

soundsRef.current
.filter(sound => sound.active)
.forEach(initialSound => {
const targetVolume = Math.random()
const volumeSteps = calculateVolumeSteps(
initialSound.volume,
targetVolume,
NUM_STEPS
)

const setVolumeStep = (sound, index) => {
if (index < volumeSteps.length) {
// Fetch the most recent value of the sound
const currentSound = soundsRef.current.find(s => s.id === sound.id);
if (currentSound && currentSound.active) {
const updatedVolume = volumeSteps[index];
const updatedSound = { ...currentSound, volume: updatedVolume };
setSound(updatedSound);
// add next timeout only if this one is successfull
const timeoutId = setTimeout(() => {
setVolumeStep(currentSound, index + 1);
}, stepDuration);

timeoutsRef.current.push(timeoutId);
}
if (index < volumeSteps.length) {
// Fetch the most recent value of the sound
const currentSound = soundsRef.current.find(s => s.id === sound.id)
if (currentSound && currentSound.active) {
const updatedVolume = volumeSteps[index]
const updatedSound = { ...currentSound, volume: updatedVolume }
setSound(updatedSound)
// add next timeout only if this one is successfull
const timeoutId = setTimeout(() => {
setVolumeStep(currentSound, index + 1)
}, stepDuration)

timeoutsRef.current.push(timeoutId)
}
};
}
}

setVolumeStep(initialSound, 0);
});
}
setVolumeStep(initialSound, 0)
})
}

function randomizeVolumes() {
// Total duration for volume change
Expand Down

0 comments on commit 22a62b2

Please sign in to comment.