Skip to content

Commit 8e5f11e

Browse files
authored
Fix artist coin exclusives loading (#13788)
1 parent 3fc74fc commit 8e5f11e

4 files changed

Lines changed: 51 additions & 18 deletions

File tree

packages/common/src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export * from './tan-query/events'
3232

3333
// Explore
3434
export * from './tan-query/collection/useExploreContent'
35+
export * from './tan-query/collection/useFeaturedArtistCoinTracks'
3536

3637
// Lineups
3738
export * from './tan-query/lineups/useFeed'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useTracks } from '../tracks/useTracks'
2+
import type { QueryOptions } from '../types'
3+
4+
import { useExploreContent } from './useExploreContent'
5+
6+
/**
7+
* Combines useExploreContent and useTracks to fetch featured artist coin tracks
8+
* with prefetched track data. Use this instead of useExploreContent + useTracks
9+
* separately to avoid the skeleton → nothing → tracks flash caused by the
10+
* two-step fetch (explore content IDs → track metadata).
11+
*
12+
* Shared across web and mobile.
13+
*/
14+
export const useFeaturedArtistCoinTracks = (options?: QueryOptions) => {
15+
const { data: exploreContent } = useExploreContent(options)
16+
17+
const tracksQuery = useTracks(exploreContent?.featuredArtistCoinTracks, {
18+
...options,
19+
enabled: options?.enabled !== false
20+
})
21+
22+
return {
23+
trackIds: tracksQuery.data?.map((track) => track.track_id),
24+
tracks: tracksQuery.data,
25+
byId: tracksQuery.byId,
26+
isPending: tracksQuery.isPending,
27+
isSuccess: tracksQuery.isSuccess,
28+
isError: tracksQuery.isError
29+
}
30+
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { useExploreContent } from '@audius/common/api'
3+
import { useFeaturedArtistCoinTracks } from '@audius/common/api'
44
import { exploreMessages as messages } from '@audius/common/messages'
55
import { QueueSource } from '@audius/common/store'
66

@@ -12,19 +12,19 @@ import { TrackTileCarousel } from './TrackTileCarousel'
1212
export const FeaturedArtistCoinTracks = () => {
1313
const { InViewWrapper, inView } =
1414
useExploreSectionTracking('Artist Coin Tracks')
15-
const { data, isPending } = useExploreContent({ enabled: inView })
15+
const { trackIds, isPending } = useFeaturedArtistCoinTracks({
16+
enabled: inView
17+
})
1618

1719
return (
1820
<InViewWrapper>
19-
{data?.featuredArtistCoinTracks.length ? (
20-
<ExploreSection title={messages.artistCoinExclusives}>
21-
<TrackTileCarousel
22-
tracks={data?.featuredArtistCoinTracks}
23-
isLoading={isPending}
24-
source={QueueSource.EXPLORE}
25-
/>
26-
</ExploreSection>
27-
) : null}
21+
<ExploreSection title={messages.artistCoinExclusives}>
22+
<TrackTileCarousel
23+
tracks={trackIds}
24+
isLoading={isPending}
25+
source={QueueSource.EXPLORE}
26+
/>
27+
</ExploreSection>
2828
</InViewWrapper>
2929
)
3030
}

packages/web/src/pages/search-explore-page/components/desktop/ArtistCoinTracksSection.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useExploreContent } from '@audius/common/api'
1+
import { useFeaturedArtistCoinTracks } from '@audius/common/api'
22
import { exploreMessages as messages } from '@audius/common/messages'
33

44
import { Carousel } from './Carousel'
@@ -8,20 +8,22 @@ import { useExploreSectionTracking } from './useExploreSectionTracking'
88
export const ArtistCoinTracksSection = () => {
99
const { ref, inView } = useExploreSectionTracking('Artist Coin Tracks')
1010

11-
const { data, isLoading, isError, isSuccess } = useExploreContent({
12-
enabled: inView
13-
})
11+
const {
12+
trackIds = [],
13+
isPending,
14+
isError
15+
} = useFeaturedArtistCoinTracks({ enabled: inView })
1416

15-
if (isError || (isSuccess && !data?.featuredArtistCoinTracks?.length)) {
17+
if (isError || (!isPending && !trackIds?.length)) {
1618
return null
1719
}
1820

1921
return (
2022
<Carousel ref={ref} title={messages.artistCoinExclusives}>
21-
{!inView || isLoading || !data ? (
23+
{!inView || isPending ? (
2224
<TileSkeletons noShimmer />
2325
) : (
24-
<TilePairs data={data.featuredArtistCoinTracks} />
26+
<TilePairs data={trackIds} />
2527
)}
2628
</Carousel>
2729
)

0 commit comments

Comments
 (0)