diff --git a/components/Album/index.tsx b/components/Album/index.tsx index 4a6e7108..eb174bad 100644 --- a/components/Album/index.tsx +++ b/components/Album/index.tsx @@ -2,7 +2,7 @@ import { HomeAlbumProps } from '../types' import { YStack, XStack, Separator, getToken } from 'tamagui' import { ItemSortBy } from '@jellyfin/sdk/lib/generated-client/models' import { H5, Text } from '../Global/helpers/text' -import { FlatList } from 'react-native' +import { FlatList, SectionList } from 'react-native' import { RunTimeTicks } from '../Global/helpers/time-codes' import Track from '../Global/components/track' import { useSafeAreaFrame } from 'react-native-safe-area-context' @@ -11,9 +11,10 @@ import { useQuery } from '@tanstack/react-query' import { QueryKeys } from '../../enums/query-keys' import { getImageApi, getItemsApi } from '@jellyfin/sdk/lib/utils/api' import Client from '../../api/client' -import { useMemo } from 'react' +import { useEffect, useMemo } from 'react' import { ItemCard } from '../Global/components/item-card' import { Image } from 'expo-image' +import { groupBy, isEqual } from 'lodash' export function AlbumScreen({ route, navigation }: HomeAlbumProps): React.JSX.Element { const { album } = route.params @@ -37,65 +38,79 @@ export function AlbumScreen({ route, navigation }: HomeAlbumProps): React.JSX.El parentId: album.Id!, sortBy, }) - .then((response) => { - return response.data.Items ? response.data.Items! : [] + .then(({ data }) => { + return data.Items ? data.Items : [] }) }, }) return ( - item.Id!} - numColumns={1} + sections={ + tracks + ? Object.keys(groupBy(tracks, (track) => track.ParentIndexNumber ?? 0)).map( + (discNumber, index) => { + return { + title: discNumber, + data: tracks.filter((track) => + isEqual( + discNumber, + (track.ParentIndexNumber ?? 0).toString(), + ), + ), + } + }, + ) + : [{ title: '1', data: [] }] + } + keyExtractor={(item, index) => item.Id! + index} ItemSeparatorComponent={() => } - ListHeaderComponent={useMemo(() => { - return ( - - + renderSectionHeader={({ section }) => {`Disc ${section.title}`}} + ListHeaderComponent={ + + -
{album.Name ?? 'Untitled Album'}
+
{album.Name ?? 'Untitled Album'}
- - {album.ProductionYear?.toString() ?? ''} - + + {album.ProductionYear?.toString() ?? ''} + - item.Id!} - data={album.ArtistItems} - renderItem={({ index, item: artist }) => ( - { - navigation.navigate('Artist', { - artist, - }) - }} - /> - )} - /> -
- ) - }, [album])} + item.Id!} + data={album.ArtistItems} + renderItem={({ index, item: artist }) => ( + { + navigation.navigate('Artist', { + artist, + }) + }} + /> + )} + /> +
+ } renderItem={({ item: track, index }) => ( {album.RunTimeTicks} } + contentContainerStyle={{ + marginHorizontal: 4, + }} /> ) } diff --git a/components/Global/components/track.tsx b/components/Global/components/track.tsx index 38eb946d..8ffb6c77 100644 --- a/components/Global/components/track.tsx +++ b/components/Global/components/track.tsx @@ -47,7 +47,6 @@ export default function Track({ onRemove, }: TrackProps): React.JSX.Element { const theme = useTheme() - const { width } = useSafeAreaFrame() const { nowPlaying, playQueue, usePlayNewQueue } = usePlayerContext() const isPlaying = nowPlaying?.item.Id === track.Id @@ -82,7 +81,6 @@ export default function Track({ } } paddingVertical={'$2'} - marginHorizontal={'$1'} > {prependElement && ( @@ -93,8 +91,9 @@ export default function Track({ {showArtwork ? ( - + {nowPlaying?.title ?? 'Nothing Playing'} diff --git a/components/Playlist/component.tsx b/components/Playlist/component.tsx index b0578d3b..e1aa7fbd 100644 --- a/components/Playlist/component.tsx +++ b/components/Playlist/component.tsx @@ -194,6 +194,9 @@ export default function Playlist({ playlist, navigation }: PlaylistProps): React {playlist.RunTimeTicks} } + style={{ + marginHorizontal: 2, + }} /> ) } diff --git a/components/Search/component.tsx b/components/Search/component.tsx index cd8ddc8b..686c9749 100644 --- a/components/Search/component.tsx +++ b/components/Search/component.tsx @@ -111,6 +111,9 @@ export default function Search({ renderItem={({ item }) => ( )} + style={{ + marginHorizontal: 2, + }} /> ) } diff --git a/components/Search/suggestions.tsx b/components/Search/suggestions.tsx index a259559e..be3a89f2 100644 --- a/components/Search/suggestions.tsx +++ b/components/Search/suggestions.tsx @@ -51,6 +51,9 @@ export default function Suggestions(props: SuggestionsProps): React.JSX.Element renderItem={({ item }) => { return }} + style={{ + marginHorizontal: 2, + }} /> ) }