import { AlbumContextPressable } from '@app/components/ContextMenu' import CoverArt from '@app/components/CoverArt' import GradientScrollView from '@app/components/GradientScrollView' import Header from '@app/components/Header' import NothingHere from '@app/components/NothingHere' import { useQueryHomeLists } from '@app/hooks/query' import { Album } from '@app/models/library' import { useStoreDeep } from '@app/state/store' import colors from '@app/styles/colors' import font from '@app/styles/font' import { GetAlbumList2TypeBase, GetAlbumListType } from '@app/subsonic/params' import { useNavigation } from '@react-navigation/native' import equal from 'fast-deep-equal/es6/react' import React from 'react' import { RefreshControl, ScrollView, StyleSheet, Text, View } from 'react-native' import { useSafeAreaInsets } from 'react-native-safe-area-context' const titles: { [key in GetAlbumListType]?: string } = { recent: 'Recently Played', random: 'Random Albums', frequent: 'Frequently Played', starred: 'Starred Albums', } const AlbumItem = React.memo<{ album: Album }>(({ album }) => { const navigation = useNavigation() return ( navigation.navigate('album', { id: album.id, title: album.name, album })}> {album.name} {album.artist} ) }, equal) const Category = React.memo<{ type: string albums: Album[] }>(({ type, albums }) => { const Albums = () => ( {albums.map(a => ( ))} ) const Nothing = () => ( ) return (
{titles[type as GetAlbumListType] || ''}
{albums.length > 0 ? : }
) }, equal) const Home = () => { const types = useStoreDeep(store => store.settings.screens.home.listTypes) const listQueries = useQueryHomeLists(types as GetAlbumList2TypeBase[], 20) const paddingTop = useSafeAreaInsets().top return ( q.isLoading)} onRefresh={() => listQueries.forEach(q => q.refetch())} colors={[colors.accent, colors.accentLow]} progressViewOffset={paddingTop} /> }> {types.map(type => { const query = listQueries.find(list => list.data?.type === type) return })} ) } const styles = StyleSheet.create({ scroll: { flex: 1, }, content: { paddingBottom: 20, }, header: { paddingHorizontal: 20, }, category: { // marginTop: 12, }, nothingHereContent: { width: '100%', height: 190, justifyContent: 'center', alignItems: 'center', }, artScroll: { height: 190, }, artScrollContent: { paddingLeft: 20, }, item: { flex: 1, marginRight: 10, width: 150, }, title: { fontFamily: font.semiBold, fontSize: 13, color: colors.text.primary, marginTop: 4, }, subtitle: { fontFamily: font.regular, fontSize: 12, color: colors.text.secondary, }, }) export default Home