refactor(audio): Phase 4 — unify song tracking, remove compat aliases
playerStore: remove currentPlayingSongId/currentPlayingBandId/setCurrentPlayingSong. Single pair (currentSongId/currentBandId) now set exclusively when play() is called, not when the page opens. This means MiniPlayer and sidebar links only appear after audio has been started — correct UX for a "now playing" widget. audioService: play() calls setCurrentSong instead of setCurrentPlayingSong; cleanup() clears it. Remove isReadyForPlayback() and canAttemptPlayback() aliases — all callers now use isWaveformReady() directly. useWaveform: remove setCurrentSong call from init (store updated by play() now); restore-playback snapshot reads currentSongId/currentBandId. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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<Omit<PlayerState, 'setPlaying' | 'setCurrentTime' | 'setDuration' | 'setCurrentSong' | 'setCurrentPlayingSong' | 'reset' | 'batchUpdate'>>) => void;
|
||||
batchUpdate: (updates: Partial<Omit<PlayerState, 'setPlaying' | 'setCurrentTime' | 'setDuration' | 'setCurrentSong' | 'reset' | 'batchUpdate'>>) => void;
|
||||
}
|
||||
|
||||
export const usePlayerStore = create<PlayerState>()((set) => ({
|
||||
@@ -23,21 +22,16 @@ export const usePlayerStore = create<PlayerState>()((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
|
||||
})
|
||||
}));
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user