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

View File

@ -12,8 +12,7 @@ import { useStore } from '@app/state/store'
import { selectTrackPlayer } from '@app/state/trackplayer' import { selectTrackPlayer } from '@app/state/trackplayer'
import colors from '@app/styles/colors' import colors from '@app/styles/colors'
import font from '@app/styles/font' import font from '@app/styles/font'
import { useNavigation } from '@react-navigation/native' import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native' import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'
type SongListType = 'album' | 'playlist' type SongListType = 'album' | 'playlist'
@ -144,12 +143,6 @@ const SongListView = React.memo<{
title: string title: string
type: SongListType type: SongListType
}>(({ id, title, type }) => { }>(({ id, title, type }) => {
const navigation = useNavigation()
useEffect(() => {
navigation.setOptions({ title })
})
return type === 'album' ? <AlbumView id={id} title={title} /> : <PlaylistView id={id} title={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) => { mapChildrenToSongs: async (children, coverArt) => {
const songMaps: Promise<Song>[] = [] const albumIds = children.reduce((acc, val) => {
for (const child of children) { if (val.albumId && !(val.albumId in acc)) {
songMaps.push(get().mapChildToSong(child, coverArt)) acc[val.albumId] = get().getAlbumCoverArt(val.albumId)
} }
return await Promise.all(songMaps) return acc
}, {} as Record<string, Promise<string | undefined>>)
await Promise.all(Object.values(albumIds))
const songs: Song[] = []
for (const child of children) {
songs.push(await get().mapChildToSong(child, coverArt || (await get().getAlbumCoverArt(child.albumId))))
}
return songs
}, },
mapArtistID3toArtist: artist => { mapArtistID3toArtist: artist => {