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 { useActiveServerRefresh } from '@app/hooks/server'
import { AlbumListItem } from '@app/models/music'
import { selectMusic } from '@app/state/music'
import { selectSettings } from '@app/state/settings'
import { useStore } from '@app/state/store'
import colors from '@app/styles/colors'
import font from '@app/styles/font'
import { GetAlbumListType } from '@app/subsonic/params'
import { useNavigation } from '@react-navigation/native'
import React, { useCallback } from 'react'
import { RefreshControl, ScrollView, StatusBar, StyleSheet, Text, View } from 'react-native'
const titles: { [key in GetAlbumListType]?: string } = {
recent: 'Recent Albums',
random: 'Random Albums',
frequent: 'Frequent Albums',
starred: 'Starred Albums',
}
const AlbumItem = React.memo<{
album: AlbumListItem
}>(({ album }) => {
const navigation = useNavigation()
return (
navigation.navigate('album', { id: album.id, title: album.name })}>
{album.name}
{album.artist}
)
})
const Category = React.memo<{
name?: string
data: AlbumListItem[]
}>(({ name, data }) => {
const Albums = () => (
{data.map(album => (
))}
)
const Nothing = () => (
)
return (
{data.length > 0 ? : }
)
})
const Home = () => {
const types = useStore(selectSettings.homeLists)
const lists = useStore(selectMusic.homeLists)
const updating = useStore(selectMusic.homeListsUpdating)
const update = useStore(selectMusic.fetchHomeLists)
const clear = useStore(selectMusic.clearHomeLists)
useActiveServerRefresh(
useCallback(() => {
clear()
update()
}, [clear, update]),
)
return (
}>
{types.map(type => (
))}
)
}
const styles = StyleSheet.create({
scroll: {
flex: 1,
},
scrollContentContainer: {
paddingTop: StatusBar.currentHeight,
},
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