swtiched back to 2 sizes for images

siwtched to Image for now to avoid double caching from FastImage
This commit is contained in:
austinried
2021-08-19 11:21:53 +09:00
parent 25b95a4b65
commit 79a42b9adb
12 changed files with 155 additions and 116 deletions

View File

@@ -1,7 +1,4 @@
import { CacheItemTypeKey } from '@app/models/music'
import { selectCache } from '@app/state/cache'
import { selectMusic } from '@app/state/music'
import { selectSettings } from '@app/state/settings'
import { Store, useStore } from '@app/state/store'
import { useCallback, useEffect } from 'react'
@@ -63,62 +60,3 @@ export const useStarred = (id: string, type: string) => {
),
)
}
const useFileRequest = (key: CacheItemTypeKey, id: string) => {
const file = useStore(
useCallback(
(store: Store) => {
const activeServerId = store.settings.activeServer
if (!activeServerId) {
return
}
return store.cacheFiles[activeServerId][key][id]
},
[key, id],
),
)
const request = useStore(
useCallback(
(store: Store) => {
const activeServerId = store.settings.activeServer
if (!activeServerId) {
return
}
return store.cacheRequests[activeServerId][key][id]
},
[key, id],
),
)
return { file, request }
}
export const useCoverArtFile = (coverArt: string = '-1') => {
const { file, request } = useFileRequest('coverArt', coverArt)
const client = useStore(selectSettings.client)
const cacheItem = useStore(selectCache.cacheItem)
useEffect(() => {
if (!file && client) {
cacheItem('coverArt', coverArt, () => client.getCoverArtUri({ id: coverArt }))
}
}, [cacheItem, client, coverArt, file])
return { file, request }
}
export const useArtistArtFile = (artistId: string) => {
const artistInfo = useArtistInfo(artistId)
const { file, request } = useFileRequest('artistArt', artistId)
const cacheItem = useStore(selectCache.cacheItem)
useEffect(() => {
if (!file && artistInfo && artistInfo.largeImageUrl) {
cacheItem('artistArt', artistId, artistInfo.largeImageUrl)
}
}, [artistId, artistInfo, artistInfo?.largeImageUrl, cacheItem, file])
return { file, request }
}