mirror of
https://github.com/austinried/subtracks.git
synced 2026-03-28 07:12:43 +01:00
persist cache map for cover art
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -211,7 +211,7 @@ export const useSetQueue = () => {
|
||||
return
|
||||
}
|
||||
|
||||
const coverArtPaths: { [coverArt: string]: string } = {}
|
||||
const coverArtPaths: { [coverArt: string]: string | undefined } = {}
|
||||
for (const s of songs) {
|
||||
if (!s.coverArt) {
|
||||
continue
|
||||
@@ -271,14 +271,17 @@ export const useIsPlaying = (contextId: string | undefined, track: number) => {
|
||||
return contextId === queueContextId && track === currentTrackIdx
|
||||
}
|
||||
|
||||
function mapSongToTrack(song: Song, coverArtPaths: { [coverArt: string]: string }): TrackExt {
|
||||
function mapSongToTrack(song: Song, coverArtPaths: { [coverArt: string]: string | undefined }): TrackExt {
|
||||
return {
|
||||
id: song.id,
|
||||
title: song.title,
|
||||
artist: song.artist || 'Unknown Artist',
|
||||
album: song.album || 'Unknown Album',
|
||||
url: song.streamUri,
|
||||
artwork: song.coverArt ? `file://${coverArtPaths[song.coverArt]}` : require('@res/fallback.png'),
|
||||
artwork:
|
||||
song.coverArt && coverArtPaths[song.coverArt]
|
||||
? `file://${coverArtPaths[song.coverArt]}`
|
||||
: require('@res/fallback.png'),
|
||||
coverArt: song.coverArt,
|
||||
duration: song.duration,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user