Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
f5fbaae66f
commit
60a88d4eb2
@ -364,7 +364,15 @@ export const disabledSongsService = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
debugLog('Saving disabled song:', disabledSong);
|
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');
|
debugLog('Disabled song saved successfully');
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -372,7 +380,15 @@ export const disabledSongsService = {
|
|||||||
removeDisabledSong: async (controllerName: string, songPath: string) => {
|
removeDisabledSong: async (controllerName: string, songPath: string) => {
|
||||||
const songKey = disabledSongsService.generateSongKey(songPath);
|
const songKey = disabledSongsService.generateSongKey(songPath);
|
||||||
const disabledSongRef = ref(database, `controllers/${controllerName}/disabledSongs/${songKey}`);
|
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
|
// Check if a song is disabled
|
||||||
|
|||||||
@ -38,21 +38,12 @@ export const useDisabledSongs = () => {
|
|||||||
const unsubscribe = disabledSongsService.subscribeToDisabledSongs(
|
const unsubscribe = disabledSongsService.subscribeToDisabledSongs(
|
||||||
controllerName,
|
controllerName,
|
||||||
(songs) => {
|
(songs) => {
|
||||||
// Only update if the data has actually changed
|
try {
|
||||||
setDisabledSongs(prevSongs => {
|
setDisabledSongs(songs);
|
||||||
if (JSON.stringify(prevSongs) !== JSON.stringify(songs)) {
|
setDisabledSongPaths(new Set(Object.values(songs).map((song: DisabledSong) => song.path)));
|
||||||
return songs;
|
} catch (error) {
|
||||||
}
|
console.error('Error updating disabled songs state:', error);
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user