Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>

This commit is contained in:
Matt Bruce 2025-07-19 13:36:02 -05:00
parent f5fbaae66f
commit 60a88d4eb2
2 changed files with 24 additions and 17 deletions

View File

@ -364,7 +364,15 @@ export const disabledSongsService = {
};
debugLog('Saving disabled song:', disabledSong);
await set(disabledSongRef, disabledSong);
// Add timeout to prevent hanging
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => reject(new Error('Operation timed out')), 10000);
});
const savePromise = set(disabledSongRef, disabledSong);
await Promise.race([savePromise, timeoutPromise]);
debugLog('Disabled song saved successfully');
},
@ -372,7 +380,15 @@ export const disabledSongsService = {
removeDisabledSong: async (controllerName: string, songPath: string) => {
const songKey = disabledSongsService.generateSongKey(songPath);
const disabledSongRef = ref(database, `controllers/${controllerName}/disabledSongs/${songKey}`);
await remove(disabledSongRef);
// Add timeout to prevent hanging
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => reject(new Error('Operation timed out')), 10000);
});
const removePromise = remove(disabledSongRef);
await Promise.race([removePromise, timeoutPromise]);
},
// Check if a song is disabled

View File

@ -38,21 +38,12 @@ export const useDisabledSongs = () => {
const unsubscribe = disabledSongsService.subscribeToDisabledSongs(
controllerName,
(songs) => {
// Only update if the data has actually changed
setDisabledSongs(prevSongs => {
if (JSON.stringify(prevSongs) !== JSON.stringify(songs)) {
return songs;
}
return prevSongs;
});
setDisabledSongPaths(prevPaths => {
const newPaths = new Set(Object.values(songs).map((song: DisabledSong) => song.path));
if (JSON.stringify(Array.from(prevPaths)) !== JSON.stringify(Array.from(newPaths))) {
return newPaths;
}
return prevPaths;
});
try {
setDisabledSongs(songs);
setDisabledSongPaths(new Set(Object.values(songs).map((song: DisabledSong) => song.path)));
} catch (error) {
console.error('Error updating disabled songs state:', error);
}
}
);