optimize gathering album art a bit

This commit is contained in:
austinried 2021-08-20 12:52:57 +09:00
parent 06e84fec8d
commit 694d730ebd
3 changed files with 16 additions and 14 deletions

View File

@ -10,7 +10,7 @@ export const useArtistInfo = (id: string) => {
if (!artistInfo) {
fetchArtistInfo(id)
}
})
}, [artistInfo, fetchArtistInfo, id])
return artistInfo
}
@ -23,7 +23,7 @@ export const useAlbumWithSongs = (id: string) => {
if (!album) {
fetchAlbum(id)
}
})
}, [album, fetchAlbum, id])
return album
}
@ -36,7 +36,7 @@ export const usePlaylistWithSongs = (id: string) => {
if (!playlist) {
fetchPlaylist(id)
}
})
}, [fetchPlaylist, id, playlist])
return playlist
}

View File

@ -12,8 +12,7 @@ import { useStore } from '@app/state/store'
import { selectTrackPlayer } from '@app/state/trackplayer'
import colors from '@app/styles/colors'
import font from '@app/styles/font'
import { useNavigation } from '@react-navigation/native'
import React, { useEffect, useState } from 'react'
import React, { useState } from 'react'
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'
type SongListType = 'album' | 'playlist'
@ -144,12 +143,6 @@ const SongListView = React.memo<{
title: string
type: SongListType
}>(({ id, title, type }) => {
const navigation = useNavigation()
useEffect(() => {
navigation.setOptions({ title })
})
return type === 'album' ? <AlbumView id={id} title={title} /> : <PlaylistView id={id} title={title} />
})

View File

@ -55,11 +55,20 @@ export const createMusicMapSlice = (set: SetState<Store>, get: GetState<Store>):
},
mapChildrenToSongs: async (children, coverArt) => {
const songMaps: Promise<Song>[] = []
const albumIds = children.reduce((acc, val) => {
if (val.albumId && !(val.albumId in acc)) {
acc[val.albumId] = get().getAlbumCoverArt(val.albumId)
}
return acc
}, {} as Record<string, Promise<string | undefined>>)
await Promise.all(Object.values(albumIds))
const songs: Song[] = []
for (const child of children) {
songMaps.push(get().mapChildToSong(child, coverArt))
songs.push(await get().mapChildToSong(child, coverArt || (await get().getAlbumCoverArt(child.albumId))))
}
return await Promise.all(songMaps)
return songs
},
mapArtistID3toArtist: artist => {