persist cache map for cover art

This commit is contained in:
austinried
2021-08-13 16:19:30 +09:00
parent d1824a70be
commit 9cacc4de36
7 changed files with 114 additions and 71 deletions

View File

@@ -63,16 +63,32 @@ export const useStarred = (id: string, type: string) => {
}
export const useCoverArtFile = (coverArt: string = '-1') => {
const file = useStore(useCallback((state: Store) => state.cachedCoverArt[coverArt], [coverArt]))
const existing = useStore(
useCallback(
(state: Store) => {
const activeServerId = state.settings.activeServer
if (!activeServerId) {
return
}
return state.cache[activeServerId].files.coverArt[coverArt]
},
[coverArt],
),
)
const progress = useStore(useCallback((state: Store) => state.cachedCoverArt[coverArt], [coverArt]))
const cacheCoverArt = useStore(selectCache.cacheCoverArt)
useEffect(() => {
if (!file) {
if (!existing) {
cacheCoverArt(coverArt)
}
})
return file
if (existing && progress && progress.promise !== undefined) {
return
}
return existing
}
export const useArtistCoverArtFile = (artistId: string) => {