fix: track a playback currentIndex so prev and repeat-all work
next() did `queue.slice(idx + 1)`, so the current track was always queue[0]. prev()'s `idx > 0` guard could therefore never pass after an auto-advance — Previous did nothing, ever — and repeat: 'all' jumped to queue[0], which is the track that just finished, looping the last track of an album instead of restarting it. Replaced with a currentIndex cursor; the queue is no longer trimmed behind the playhead. The old slice did serve a purpose — bounding Vibe-prefetch growth — so that is preserved as a MAX_HISTORY = 50 cap that drops the oldest entries and re-bases the index, rather than dropped outright. setQueue/playTrack/setCurrentTrack recompute the cursor, next()/prev() fall back to findIndex if it drifts, and shuffle now picks by index so the cursor stays valid. Consumer audit: NowPlayingPanel and Vibe.tsx already derived position via findIndex and needed no change. TrackRow.handlePlay did `setQueue(queue.slice(index))`, which re-broke prev at the point of click even with the store fixed; it now passes the intact queue. This commit also includes a pre-existing uncommitted fix from the working tree (not authored by Claude): the end-of-queue auto-resume loop, which stops playback at the end of the queue instead of restarting. It is correct and independent of the cursor bug, and is preserved verbatim here. REVIEW-2026-07-30.md finding 7. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,7 @@ interface TrackRowProps {
|
||||
showVibe?: boolean;
|
||||
}
|
||||
|
||||
export function TrackRow({ track, queue, index, showActions = true, variant = 'default', showVibe = false }: TrackRowProps) {
|
||||
export function TrackRow({ track, queue, showActions = true, variant = 'default', showVibe = false }: TrackRowProps) {
|
||||
const { setQueue, playTrack, play, pause, currentTrack, isPlaying } = usePlaybackStore();
|
||||
const dislikeTrack = useDislikeTrack();
|
||||
const router = useRouter();
|
||||
@@ -35,7 +35,9 @@ export function TrackRow({ track, queue, index, showActions = true, variant = 'd
|
||||
|
||||
const handlePlay = () => {
|
||||
if (isCurrent) { isPlaying ? pause() : play(); return; }
|
||||
setQueue(queue.slice(index));
|
||||
// Queue the whole list and start at this track, so Previous can walk back
|
||||
// into the tracks before it.
|
||||
setQueue(queue);
|
||||
playTrack(track);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user