Skip to content

Commit 030b33a

Browse files
authored
fix(mobile): queue the track-page lineup from the hero Play button (#14447)
1 parent 7de135c commit 030b33a

1 file changed

Lines changed: 43 additions & 11 deletions

File tree

packages/mobile/src/screens/track-screen/TrackScreenDetailsTile.tsx

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
useStems,
88
useCurrentUserId,
99
useFanClub,
10-
useTrackDownloadCount
10+
useTrackDownloadCount,
11+
useTrackPageLineup,
12+
getTrackPageLineupQueryKey
1113
} from '@audius/common/api'
1214
import { useCurrentTrack, useGatedContentAccess } from '@audius/common/hooks'
1315
import {
@@ -29,7 +31,7 @@ import type {
2931
User,
3032
TokenGatedConditions
3133
} from '@audius/common/models'
32-
import type { CommonState } from '@audius/common/store'
34+
import type { CommonState, PlaybackTrack } from '@audius/common/store'
3335
import {
3436
playbackSelectors,
3537
reachabilitySelectors,
@@ -319,6 +321,18 @@ export const TrackScreenDetailsTile = ({
319321

320322
const currentQueueItem = useSelector(getCurrentQueueItem)
321323
const currentTrack = useCurrentTrack()
324+
325+
// Subscribe to the same lineup that renders below the track so the hero
326+
// play button can hand the related tracks (More By + You Might Also Like
327+
// / Remixes) to the player as a queue. The query is shared with
328+
// TrackScreenLineup via the tanquery cache, so this does not re-fetch.
329+
// `enabled: isReachable` keeps the fetch off when offline — matching the
330+
// visibility gate on TrackScreenLineup in TrackScreen.tsx.
331+
const { trackIds: lineupTrackIds } = useTrackPageLineup(
332+
{ trackId },
333+
{ enabled: !!isReachable }
334+
)
335+
322336
const play = useCallback(
323337
({ isPreview = false } = {}) => {
324338
if (isLineupLoading) return
@@ -334,18 +348,35 @@ export const TrackScreenDetailsTile = ({
334348
dispatch(playbackActions.play())
335349
recordPlay(trackId)
336350
} else {
337-
// Matches legacy track page lineup prefix.
338-
const playbackSource = 'TRACK_TRACKS'
351+
// Hero gets the legacy 'TRACK_TRACKS' source so its uid (built in
352+
// TrackScreen via makeStableUid(..., 'TRACK_TRACKS')) still matches.
353+
// The related tracks below render through TrackLineup with
354+
// 'TRACK_PAGE_MORE_BY' — use the same source for those queue entries
355+
// so the lineup tile highlights track auto-advance.
356+
const heroSource = 'TRACK_TRACKS'
357+
const relatedSource = 'TRACK_PAGE_MORE_BY'
358+
const hasLineup =
359+
!isPreview &&
360+
lineupTrackIds.length > 1 &&
361+
lineupTrackIds[0] === trackId
362+
const tracks: PlaybackTrack[] = hasLineup
363+
? [
364+
{ trackId, source: heroSource },
365+
...lineupTrackIds.slice(1).map((id) => ({
366+
trackId: id,
367+
source: relatedSource
368+
}))
369+
]
370+
: [{ trackId, source: heroSource }]
339371
dispatch(
340372
playbackActions.playFrom({
341-
tracks: [
342-
{
343-
trackId,
344-
source: playbackSource
345-
}
346-
],
373+
tracks,
347374
startIndex: 0,
348-
querySource: null
375+
querySource: hasLineup
376+
? {
377+
queryKey: [...getTrackPageLineupQueryKey(trackId)] as unknown[]
378+
}
379+
: null
349380
})
350381
)
351382
recordPlay(trackId, true, true)
@@ -359,6 +390,7 @@ export const TrackScreenDetailsTile = ({
359390
currentQueueItem.trackId,
360391
currentTrack,
361392
trackId,
393+
lineupTrackIds,
362394
dispatch
363395
]
364396
)

0 commit comments

Comments
 (0)