import { useArtistCoverArtFile, useCoverArtFile } from '@app/hooks/music' import { DownloadFile } from '@app/state/music' import colors from '@app/styles/colors' import React, { useCallback, useEffect, useState } from 'react' import { ActivityIndicator, StyleSheet, View, ViewStyle } from 'react-native' import FastImage, { ImageStyle } from 'react-native-fast-image' type BaseProps = { style?: ViewStyle imageStyle?: ImageStyle resizeMode?: keyof typeof FastImage.resizeMode round?: boolean } type ArtistCoverArtProps = BaseProps & { type: 'artist' artistId: string } type CoverArtProps = BaseProps & { type: 'cover' coverArt?: string } const Image: React.FC<{ file?: DownloadFile } & BaseProps> = ({ file, style, imageStyle, resizeMode }) => { const [source, setSource] = useState( file && file.progress === 1 ? { uri: `file://${file.path}` } : require('@res/fallback.png'), ) useEffect(() => { if (file && file.progress === 1) { setSource({ uri: `file://${file.path}` }) } }, [file]) return ( <> { setSource(require('@res/fallback.png')) }} /> ) } const ArtistImage = React.memo(props => { const file = useArtistCoverArtFile(props.artistId) return }) const CoverArtImage = React.memo(props => { const file = useCoverArtFile(props.coverArt) return }) const CoverArt: React.FC = props => { const viewStyles = [props.style] if (props.round) { viewStyles.push(styles.round) } const coverArtImage = useCallback(() => , [props]) const artistImage = useCallback(() => , [props]) let ImageComponent switch (props.type) { case 'artist': ImageComponent = artistImage break default: ImageComponent = coverArtImage break } return ( ) } const styles = StyleSheet.create({ round: { overflow: 'hidden', borderRadius: 1000, }, indicator: { height: '100%', width: '100%', position: 'absolute', }, }) export default React.memo(CoverArt)