mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 06:52:43 +01:00
use ids for lists, pull state later
This commit is contained in:
@@ -4,13 +4,11 @@ import GradientScrollView from '@app/components/GradientScrollView'
|
|||||||
import Header from '@app/components/Header'
|
import Header from '@app/components/Header'
|
||||||
import NothingHere from '@app/components/NothingHere'
|
import NothingHere from '@app/components/NothingHere'
|
||||||
import { useActiveServerRefresh } from '@app/hooks/server'
|
import { useActiveServerRefresh } from '@app/hooks/server'
|
||||||
import { Album } from '@app/models/library'
|
|
||||||
import { selectSettings } from '@app/state/settings'
|
import { selectSettings } from '@app/state/settings'
|
||||||
import { useStore, useStoreDeep } from '@app/state/store'
|
import { useStore, useStoreDeep } from '@app/state/store'
|
||||||
import colors from '@app/styles/colors'
|
import colors from '@app/styles/colors'
|
||||||
import font from '@app/styles/font'
|
import font from '@app/styles/font'
|
||||||
import { GetAlbumList2TypeBase, GetAlbumListType } from '@app/subsonic/params'
|
import { GetAlbumList2TypeBase, GetAlbumListType } from '@app/subsonic/params'
|
||||||
import { mapById } from '@app/util/state'
|
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import equal from 'fast-deep-equal/es6/react'
|
import equal from 'fast-deep-equal/es6/react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
@@ -26,9 +24,14 @@ const titles: { [key in GetAlbumListType]?: string } = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AlbumItem = React.memo<{
|
const AlbumItem = React.memo<{
|
||||||
album: Album
|
id: string
|
||||||
}>(({ album }) => {
|
}>(({ id }) => {
|
||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
|
const album = useStoreDeep(useCallback(store => store.entities.albums[id], [id]))
|
||||||
|
|
||||||
|
if (!album) {
|
||||||
|
return <></>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AlbumContextPressable
|
<AlbumContextPressable
|
||||||
@@ -55,7 +58,6 @@ const Category = React.memo<{
|
|||||||
type: string
|
type: string
|
||||||
}>(({ type }) => {
|
}>(({ type }) => {
|
||||||
const list = useHomeStoreDeep(useCallback(store => store.lists[type] || [], [type]))
|
const list = useHomeStoreDeep(useCallback(store => store.lists[type] || [], [type]))
|
||||||
const albums = useStoreDeep(useCallback(store => mapById(store.entities.albums, list), [list]))
|
|
||||||
|
|
||||||
const Albums = () => (
|
const Albums = () => (
|
||||||
<ScrollView
|
<ScrollView
|
||||||
@@ -64,8 +66,8 @@ const Category = React.memo<{
|
|||||||
overScrollMode={'never'}
|
overScrollMode={'never'}
|
||||||
style={styles.artScroll}
|
style={styles.artScroll}
|
||||||
contentContainerStyle={styles.artScrollContent}>
|
contentContainerStyle={styles.artScrollContent}>
|
||||||
{albums.map(album => (
|
{list.map(id => (
|
||||||
<AlbumItem key={album.id} album={album} />
|
<AlbumItem key={id} id={id} />
|
||||||
))}
|
))}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
)
|
)
|
||||||
@@ -79,7 +81,7 @@ const Category = React.memo<{
|
|||||||
return (
|
return (
|
||||||
<View style={styles.category}>
|
<View style={styles.category}>
|
||||||
<Header style={styles.header}>{titles[type as GetAlbumListType] || ''}</Header>
|
<Header style={styles.header}>{titles[type as GetAlbumListType] || ''}</Header>
|
||||||
{albums.length > 0 ? <Albums /> : <Nothing />}
|
{list.length > 0 ? <Albums /> : <Nothing />}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,24 +3,27 @@ import CoverArt from '@app/components/CoverArt'
|
|||||||
import FilterButton, { OptionData } from '@app/components/FilterButton'
|
import FilterButton, { OptionData } from '@app/components/FilterButton'
|
||||||
import GradientFlatList from '@app/components/GradientFlatList'
|
import GradientFlatList from '@app/components/GradientFlatList'
|
||||||
import { useFetchPaginatedList } from '@app/hooks/list'
|
import { useFetchPaginatedList } from '@app/hooks/list'
|
||||||
import { Album } from '@app/models/library'
|
|
||||||
import { selectSettings } from '@app/state/settings'
|
import { selectSettings } from '@app/state/settings'
|
||||||
import { useStore, useStoreDeep } from '@app/state/store'
|
import { useStore, useStoreDeep } from '@app/state/store'
|
||||||
import colors from '@app/styles/colors'
|
import colors from '@app/styles/colors'
|
||||||
import font from '@app/styles/font'
|
import font from '@app/styles/font'
|
||||||
import { GetAlbumList2Params, GetAlbumList2Type } from '@app/subsonic/params'
|
import { GetAlbumList2Params, GetAlbumList2Type } from '@app/subsonic/params'
|
||||||
import { mapById } from '@app/util/state'
|
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback } from 'react'
|
||||||
import { StyleSheet, Text, useWindowDimensions, View } from 'react-native'
|
import { StyleSheet, Text, useWindowDimensions, View } from 'react-native'
|
||||||
|
|
||||||
const AlbumItem = React.memo<{
|
const AlbumItem = React.memo<{
|
||||||
album: Album
|
id: string
|
||||||
size: number
|
size: number
|
||||||
height: number
|
height: number
|
||||||
}>(({ album, size, height }) => {
|
}>(({ id, size, height }) => {
|
||||||
|
const album = useStoreDeep(useCallback(store => store.entities.albums[id], [id]))
|
||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
|
|
||||||
|
if (!album) {
|
||||||
|
return <></>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AlbumContextPressable
|
<AlbumContextPressable
|
||||||
album={album}
|
album={album}
|
||||||
@@ -41,8 +44,8 @@ const AlbumItem = React.memo<{
|
|||||||
})
|
})
|
||||||
|
|
||||||
const AlbumListRenderItem: React.FC<{
|
const AlbumListRenderItem: React.FC<{
|
||||||
item: { album: Album; size: number; height: number }
|
item: { id: string; size: number; height: number }
|
||||||
}> = ({ item }) => <AlbumItem album={item.album} size={item.size} height={item.height} />
|
}> = ({ item }) => <AlbumItem id={item.id} size={item.size} height={item.height} />
|
||||||
|
|
||||||
const filterOptions: OptionData[] = [
|
const filterOptions: OptionData[] = [
|
||||||
{ text: 'By Name', value: 'alphabeticalByName' },
|
{ text: 'By Name', value: 'alphabeticalByName' },
|
||||||
@@ -96,7 +99,6 @@ const AlbumsList = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const { list, refreshing, refresh, fetchNextPage } = useFetchPaginatedList(fetchPage, 300)
|
const { list, refreshing, refresh, fetchNextPage } = useFetchPaginatedList(fetchPage, 300)
|
||||||
const albums = useStoreDeep(useCallback(store => mapById(store.entities.albums, list), [list]))
|
|
||||||
|
|
||||||
const layout = useWindowDimensions()
|
const layout = useWindowDimensions()
|
||||||
|
|
||||||
@@ -106,9 +108,9 @@ const AlbumsList = () => {
|
|||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<GradientFlatList
|
<GradientFlatList
|
||||||
data={albums.map(album => ({ album, size, height }))}
|
data={list.map(id => ({ id, size, height }))}
|
||||||
renderItem={AlbumListRenderItem}
|
renderItem={AlbumListRenderItem}
|
||||||
keyExtractor={item => item.album.id}
|
keyExtractor={item => item.id}
|
||||||
numColumns={3}
|
numColumns={3}
|
||||||
removeClippedSubviews={true}
|
removeClippedSubviews={true}
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
|
|||||||
Reference in New Issue
Block a user