mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 00:59:28 +01:00
filter topSongs backup search by artistName
This commit is contained in:
parent
8196704ccd
commit
87e83516a1
@ -65,14 +65,23 @@ export const useQueryArtistTopSongs = (artistName?: string) => {
|
|||||||
const querySuccess = query.isFetched && query.isSuccess && query.data && query.data.length > 0
|
const querySuccess = query.isFetched && query.isSuccess && query.data && query.data.length > 0
|
||||||
|
|
||||||
const fetchSearchResults = useFetchSearchResults()
|
const fetchSearchResults = useFetchSearchResults()
|
||||||
|
const [artistCount, albumCount, songCount] = [0, 0, 300]
|
||||||
const backupQuery = useQuery(
|
const backupQuery = useQuery(
|
||||||
qk.search(artistName || '', 0, 0, 50),
|
qk.search(artistName || '', artistCount, albumCount, songCount),
|
||||||
() => fetchSearchResults({ query: artistName as string, songCount: 50 }),
|
() => fetchSearchResults({ query: artistName as string, artistCount, albumCount, songCount }),
|
||||||
{
|
{
|
||||||
enabled: !!artistName && !query.isFetching && !querySuccess,
|
select: data => {
|
||||||
select: data =>
|
const artistNameLower = artistName?.toLowerCase()
|
||||||
|
const songs = data.songs.filter(s => s.artist?.toLowerCase() === artistNameLower)
|
||||||
|
|
||||||
// sortBy is a stable sort, so that this doesn't change order arbitrarily and re-render
|
// sortBy is a stable sort, so that this doesn't change order arbitrarily and re-render
|
||||||
_.sortBy(data.songs, [s => -(s.playCount || 0), s => -(s.averageRating || 0), s => -(s.userRating || 0)]),
|
return _.sortBy(songs, [
|
||||||
|
s => -(s.playCount || 0),
|
||||||
|
s => -(s.averageRating || 0),
|
||||||
|
s => -(s.userRating || 0),
|
||||||
|
]).slice(0, 50)
|
||||||
|
},
|
||||||
|
enabled: !!artistName && !query.isFetching && !querySuccess,
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
cacheTime: Infinity,
|
cacheTime: Infinity,
|
||||||
notifyOnChangeProps: ['data', 'isError'],
|
notifyOnChangeProps: ['data', 'isError'],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user