import { useBreakpointValue, useTheme } from 'native-base'; import { useWindowDimensions } from 'react-native'; import { TabView, SceneMap, TabBar, NavigationState, Route, SceneRendererProps, } from 'react-native-tab-view'; import { Heart, Clock, StatusUp, FolderCross } from 'iconsax-react-native'; import { Scene } from 'react-native-tab-view/lib/typescript/src/types'; import { Translate, TranslationKey } from '../i18n/i18n'; import { useQuery } from '../Queries'; import API from '../API'; import Song from '../models/Song'; import { useState } from 'react'; import MusicListCC from '../components/UI/MusicList'; const FavoritesMusic = () => { const likedSongs = useQuery(API.getLikedSongs(['artist', 'SongHistory', 'likedByUsers'])); return ( x.song)} refetch={likedSongs.refetch} isFetching={likedSongs.isFetching} /> ); }; const RecentlyPlayedMusic = () => { const playHistory = useQuery(API.getUserPlayHistory(['artist', 'SongHistory', 'likedByUsers'])); return ( x.song) as Song[]} refetch={playHistory.refetch} isFetching={playHistory.isFetching} /> ); }; const StepUpMusic = () => { const nextStep = useQuery(API.getSongSuggestions(['artist', 'SongHistory', 'likedByUsers'])); return ( ); }; const renderScene = SceneMap({ favorites: FavoritesMusic, recentlyPlayed: RecentlyPlayedMusic, stepUp: StepUpMusic, }); const getTabData = (key: string) => { switch (key) { case 'favorites': return { index: 0, icon: Heart }; case 'recentlyPlayed': return { index: 1, icon: Clock }; case 'stepUp': return { index: 2, icon: StatusUp }; default: return { index: 3, icon: FolderCross }; } }; const MusicTab = () => { const layout = useWindowDimensions(); const [index, setIndex] = useState(0); const { colors } = useTheme(); const screenSize = useBreakpointValue({ base: 'small', md: 'big' }); const isSmallScreen = screenSize === 'small'; const routes = [ { key: 'favorites', title: 'musicTabFavorites' }, { key: 'recentlyPlayed', title: 'musicTabRecentlyPlayed' }, { key: 'stepUp', title: 'musicTabStepUp' }, ]; const renderTabBar = ( props: SceneRendererProps & { navigationState: NavigationState } ) => ( & { focused: boolean; color: string; } ) => { const tabHeader = getTabData(scene.route!.key); return ( ); }} renderLabel={({ route, color }) => layout.width > 800 && ( ) } tabStyle={{ flexDirection: 'row' }} /> ); return ( ); }; export default MusicTab;