From 60a88d4eb28a0d11ea09d378f169197f4814c940 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Sat, 19 Jul 2025 13:36:02 -0500 Subject: [PATCH] Signed-off-by: Matt Bruce --- src/firebase/services.ts | 20 ++++++++++++++++++-- src/hooks/useDisabledSongs.ts | 21 ++++++--------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/firebase/services.ts b/src/firebase/services.ts index ddd13a6..3cd6b30 100644 --- a/src/firebase/services.ts +++ b/src/firebase/services.ts @@ -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 diff --git a/src/hooks/useDisabledSongs.ts b/src/hooks/useDisabledSongs.ts index 9710add..19a3e46 100644 --- a/src/hooks/useDisabledSongs.ts +++ b/src/hooks/useDisabledSongs.ts @@ -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); + } } );