From bd12cc389e79252ccf9aa86760e9651bd9b384b1 Mon Sep 17 00:00:00 2001 From: petitminion Date: Wed, 18 Jun 2025 11:36:56 +0000 Subject: [PATCH] fix(front):make soundCache reactive to allow player to get track metadata when the queue only contains one track --- front/src/composables/audio/tracks.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/front/src/composables/audio/tracks.ts b/front/src/composables/audio/tracks.ts index aeffe7020..f8ed6eabe 100644 --- a/front/src/composables/audio/tracks.ts +++ b/front/src/composables/audio/tracks.ts @@ -27,6 +27,14 @@ const soundCache = new LRUCache({ dispose: (sound) => sound.dispose() }) +// used to make soundCache reactive +const soundCacheVersion = ref(0) +function setSoundCache(trackId: number, sound: Sound) { + soundCache.set(trackId, sound) + soundCacheVersion.value++ // bump to trigger reactivity +} + + const currentTrack = ref() export const fetchTrackSources = async (id: number): Promise => { @@ -139,7 +147,7 @@ export const useTracks = createGlobalState(() => { } // Add track to the sound cache and remove from the promise cache - soundCache.set(track.id, sound) + setSoundCache(track.id, sound) soundPromises.delete(track.id) return sound @@ -224,7 +232,12 @@ export const useTracks = createGlobalState(() => { }) }) - const currentSound = computed(() => soundCache.get(currentTrack.value?.id ?? -1)) + const currentSound = computed(() => { + soundCacheVersion.value //trigger reactivity + const trackId = currentTrack.value?.id ?? -1 + const sound = soundCache.get(trackId) + return sound + }) const clearCache = () => { return soundCache.clear()