From 8fa59d2c18a0dc6ae7863b19a48068cf4e0f8624 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Tue, 22 Mar 2022 20:41:19 +0900 Subject: [PATCH] use ids for lists, pull state later --- app/screens/Home.tsx | 18 ++++++++++-------- app/screens/LibraryAlbums.tsx | 20 +++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/screens/Home.tsx b/app/screens/Home.tsx index c329744..de9a0aa 100644 --- a/app/screens/Home.tsx +++ b/app/screens/Home.tsx @@ -4,13 +4,11 @@ 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 { Album } from '@app/models/library' import { selectSettings } from '@app/state/settings' import { useStore, 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 { mapById } from '@app/util/state' import { useNavigation } from '@react-navigation/native' import equal from 'fast-deep-equal/es6/react' import produce from 'immer' @@ -26,9 +24,14 @@ const titles: { [key in GetAlbumListType]?: string } = { } const AlbumItem = React.memo<{ - album: Album -}>(({ album }) => { + id: string +}>(({ id }) => { const navigation = useNavigation() + const album = useStoreDeep(useCallback(store => store.entities.albums[id], [id])) + + if (!album) { + return <> + } return ( (({ type }) => { const list = useHomeStoreDeep(useCallback(store => store.lists[type] || [], [type])) - const albums = useStoreDeep(useCallback(store => mapById(store.entities.albums, list), [list])) const Albums = () => ( - {albums.map(album => ( - + {list.map(id => ( + ))} ) @@ -79,7 +81,7 @@ const Category = React.memo<{ return (
{titles[type as GetAlbumListType] || ''}
- {albums.length > 0 ? : } + {list.length > 0 ? : }
) }) diff --git a/app/screens/LibraryAlbums.tsx b/app/screens/LibraryAlbums.tsx index ed4bedf..e97d96f 100644 --- a/app/screens/LibraryAlbums.tsx +++ b/app/screens/LibraryAlbums.tsx @@ -3,24 +3,27 @@ import CoverArt from '@app/components/CoverArt' import FilterButton, { OptionData } from '@app/components/FilterButton' import GradientFlatList from '@app/components/GradientFlatList' import { useFetchPaginatedList } from '@app/hooks/list' -import { Album } from '@app/models/library' import { selectSettings } from '@app/state/settings' import { useStore, useStoreDeep } from '@app/state/store' import colors from '@app/styles/colors' import font from '@app/styles/font' import { GetAlbumList2Params, GetAlbumList2Type } from '@app/subsonic/params' -import { mapById } from '@app/util/state' import { useNavigation } from '@react-navigation/native' import React, { useCallback } from 'react' import { StyleSheet, Text, useWindowDimensions, View } from 'react-native' const AlbumItem = React.memo<{ - album: Album + id: string size: number height: number -}>(({ album, size, height }) => { +}>(({ id, size, height }) => { + const album = useStoreDeep(useCallback(store => store.entities.albums[id], [id])) const navigation = useNavigation() + if (!album) { + return <> + } + return ( = ({ item }) => + item: { id: string; size: number; height: number } +}> = ({ item }) => const filterOptions: OptionData[] = [ { text: 'By Name', value: 'alphabeticalByName' }, @@ -96,7 +99,6 @@ const AlbumsList = () => { ) const { list, refreshing, refresh, fetchNextPage } = useFetchPaginatedList(fetchPage, 300) - const albums = useStoreDeep(useCallback(store => mapById(store.entities.albums, list), [list])) const layout = useWindowDimensions() @@ -106,9 +108,9 @@ const AlbumsList = () => { return ( ({ album, size, height }))} + data={list.map(id => ({ id, size, height }))} renderItem={AlbumListRenderItem} - keyExtractor={item => item.album.id} + keyExtractor={item => item.id} numColumns={3} removeClippedSubviews={true} refreshing={refreshing}