import { memo } from 'react'; import { FlatList, HStack, View, useBreakpointValue, useTheme, Text, Row } from 'native-base'; import { ActivityIndicator, StyleSheet } from 'react-native'; import MusicItem from './MusicItem'; import ButtonBase from './ButtonBase'; import { ArrowDown2, ArrowRotateLeft, Cup, Icon } from 'iconsax-react-native'; import { translate } from '../../i18n/i18n'; import Song from '../../models/Song'; import { useLikeSongMutation } from '../../utils/likeSongMutation'; import { useNavigation } from '../../Navigation'; import { LoadingView } from '../Loading'; // Props type definition for MusicItemTitle. interface MusicItemTitleProps { /** Text to be displayed when the screen size is large. */ text: string; /** Icon component to be used. */ icon: Icon; /** Flag to indicate if the screen size is large enough to display additional text. */ isBigScreen: boolean; } function MusicItemTitleComponent(props: MusicItemTitleProps) { const { colors } = useTheme(); return ( {/* Conditional rendering based on screen size. */} {props.isBigScreen && ( {props.text} )} {/* Icon with color based on the current color scheme. */} ); } // MusicItemTitle component, memoized for performance. const MusicItemTitle = memo(MusicItemTitleComponent); const Header = () => { const { colors } = useTheme(); const screenSize = useBreakpointValue({ base: 'small', md: 'md', xl: 'xl' }); const isBigScreen = screenSize === 'xl'; return ( {translate('musicListTitleSong')} ); }; function MusicListCC({ musics, refetch, hasMore, isFetching, fetchMore, }: { musics?: Song[]; refetch: () => Promise; hasMore?: boolean; isFetching: boolean; fetchMore?: () => Promise; }) { const { mutateAsync } = useLikeSongMutation(); const navigation = useNavigation(); const { colors } = useTheme(); if (!musics) { return ; } return ( ( { mutateAsync({ songId: song.id, like: state }).then(() => refetch()); }} onPlay={() => navigation.navigate('Play', { songId: song.id })} style={{ marginBottom: 2 }} /> )} keyExtractor={(item) => item.id.toString()} ListFooterComponent={ hasMore ? ( {isFetching ? ( ) : ( { fetchMore?.(); }} icon={ArrowDown2} /> )} ) : null } /> ); } // Styles for the MusicList component const styles = StyleSheet.create({ container: { flex: 1, gap: 2, borderRadius: 10, }, footerContainer: { height: 60, justifyContent: 'center', alignItems: 'center', }, }); export default MusicListCC;