diff --git a/web/src/hooks/useWaveform.ts b/web/src/hooks/useWaveform.ts index a287fe8..974ff9f 100755 --- a/web/src/hooks/useWaveform.ts +++ b/web/src/hooks/useWaveform.ts @@ -41,17 +41,12 @@ export function useWaveform( try { await audioService.initialize(containerRef.current!, options.url!); - // Update global song context - if (options.songId && options.bandId) { - usePlayerStore.getState().setCurrentSong(options.songId, options.bandId); - } - // Restore playback if this song was already playing when the page loaded. // Read as a one-time snapshot — these values must NOT be reactive deps or // the effect would re-run on every time update (re-initializing WaveSurfer). const { - currentPlayingSongId, - currentPlayingBandId, + currentSongId, + currentBandId, isPlaying: wasPlaying, currentTime: savedTime, } = usePlayerStore.getState(); @@ -59,8 +54,8 @@ export function useWaveform( if ( options.songId && options.bandId && - currentPlayingSongId === options.songId && - currentPlayingBandId === options.bandId && + currentSongId === options.songId && + currentBandId === options.bandId && wasPlaying && audioService.isWaveformReady() ) { diff --git a/web/src/services/audioService.ts b/web/src/services/audioService.ts index 6169f81..2ecbc8f 100755 --- a/web/src/services/audioService.ts +++ b/web/src/services/audioService.ts @@ -86,7 +86,7 @@ class AudioService { } await this.wavesurfer.play(); if (songId && bandId) { - usePlayerStore.getState().setCurrentPlayingSong(songId, bandId); + usePlayerStore.getState().setCurrentSong(songId, bandId); } } @@ -116,19 +116,10 @@ class AudioService { return this.isReady && !!this.wavesurfer; } - // Aliases kept for callers until Phase 3 cleans them up - public isReadyForPlayback(): boolean { - return this.isWaveformReady(); - } - - public canAttemptPlayback(): boolean { - return this.isWaveformReady(); - } - public cleanup(): void { this.destroyWaveSurfer(); const store = usePlayerStore.getState(); - store.setCurrentPlayingSong(null, null); + store.setCurrentSong(null, null); store.batchUpdate({ isPlaying: false, currentTime: 0 }); } diff --git a/web/src/stores/playerStore.ts b/web/src/stores/playerStore.ts index 3d5433b..76d80cc 100755 --- a/web/src/stores/playerStore.ts +++ b/web/src/stores/playerStore.ts @@ -4,17 +4,16 @@ interface PlayerState { isPlaying: boolean; currentTime: number; duration: number; + // Set when audio starts playing; cleared on cleanup. + // Drives MiniPlayer visibility and sidebar "go to now playing" links. currentSongId: string | null; currentBandId: string | null; - currentPlayingSongId: string | null; // Track which song is actively playing - currentPlayingBandId: string | null; // Track which band's song is actively playing setPlaying: (isPlaying: boolean) => void; setCurrentTime: (currentTime: number) => void; setDuration: (duration: number) => void; setCurrentSong: (songId: string | null, bandId: string | null) => void; - setCurrentPlayingSong: (songId: string | null, bandId: string | null) => void; reset: () => void; - batchUpdate: (updates: Partial>) => void; + batchUpdate: (updates: Partial>) => void; } export const usePlayerStore = create()((set) => ({ @@ -23,21 +22,16 @@ export const usePlayerStore = create()((set) => ({ duration: 0, currentSongId: null, currentBandId: null, - currentPlayingSongId: null, - currentPlayingBandId: null, setPlaying: (isPlaying) => set({ isPlaying }), setCurrentTime: (currentTime) => set({ currentTime }), setDuration: (duration) => set({ duration }), setCurrentSong: (songId, bandId) => set({ currentSongId: songId, currentBandId: bandId }), - setCurrentPlayingSong: (songId, bandId) => set({ currentPlayingSongId: songId, currentPlayingBandId: bandId }), batchUpdate: (updates) => set(updates), - reset: () => set({ - isPlaying: false, - currentTime: 0, - duration: 0, - currentSongId: null, + reset: () => set({ + isPlaying: false, + currentTime: 0, + duration: 0, + currentSongId: null, currentBandId: null, - currentPlayingSongId: null, - currentPlayingBandId: null }) -})); \ No newline at end of file +})); diff --git a/web/tests/audioService.test.ts b/web/tests/audioService.test.ts index b61fa4e..07fd3b4 100644 --- a/web/tests/audioService.test.ts +++ b/web/tests/audioService.test.ts @@ -164,19 +164,19 @@ describe('AudioService', () => { expect(mockWs.play).toHaveBeenCalled(); }); - it('updates currentPlayingSongId/BandId in the store', async () => { + it('updates currentSongId/BandId in the store', async () => { await initService(service); await service.play('song-1', 'band-1'); const state = usePlayerStore.getState(); - expect(state.currentPlayingSongId).toBe('song-1'); - expect(state.currentPlayingBandId).toBe('band-1'); + expect(state.currentSongId).toBe('song-1'); + expect(state.currentBandId).toBe('band-1'); }); it('does not update store ids when called without ids', async () => { await initService(service); await service.play(); const state = usePlayerStore.getState(); - expect(state.currentPlayingSongId).toBeNull(); + expect(state.currentSongId).toBeNull(); }); });