import { useArtistArtFile, useCoverArtFile } from '@app/hooks/cache' import { CacheFile, CacheImageSize, CacheRequest } from '@app/models/cache' import colors from '@app/styles/colors' import React, { useState } from 'react' import { ActivityIndicator, Image, ImageResizeMode, ImageSourcePropType, ImageStyle, StyleSheet, View, ViewStyle, } from 'react-native' type BaseProps = { style?: ViewStyle imageStyle?: ImageStyle resizeMode?: ImageResizeMode round?: boolean size?: CacheImageSize } type ArtistCoverArtProps = BaseProps & { type: 'artist' artistId: string } type CoverArtProps = BaseProps & { type: 'cover' coverArt?: string } const ImageSource = React.memo<{ cache?: { file?: CacheFile; request?: CacheRequest } } & BaseProps>( ({ cache, style, imageStyle, resizeMode }) => { const [error, setError] = useState(false) let source: ImageSourcePropType if (!error && cache?.file && !cache?.request?.promise) { source = { uri: `file://${cache.file.path}`, cache: 'reload' } } else { source = require('@res/fallback.png') } return ( <> setError(true)} /> ) }, ) const ArtistImage = React.memo(props => { const cache = useArtistArtFile(props.artistId, props.size) return }) const CoverArtImage = React.memo(props => { const cache = useCoverArtFile(props.coverArt, props.size) return }) const CoverArt = React.memo(props => { const viewStyles = [props.style] if (props.round) { viewStyles.push(styles.round) } let imageComponent switch (props.type) { case 'artist': imageComponent = break default: imageComponent = break } return {imageComponent} }) const styles = StyleSheet.create({ round: { overflow: 'hidden', borderRadius: 1000, }, indicator: { height: '100%', width: '100%', position: 'absolute', }, artistImage: { backgroundColor: 'rgba(81, 28, 99, 0.4)', }, }) export default CoverArt