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:
@@ -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()
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user