Skip to content

Commit f368ba7

Browse files
Add Item Context Provider
Wrap Item Context Provider around item components: - ItemCard - ItemRow - Track This is to prepopulate our query cache with data used in the Context Sheet
1 parent 8a191b9 commit f368ba7

File tree

6 files changed

+79
-97
lines changed

6 files changed

+79
-97
lines changed

src/components/Artist/albums.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default function Albums({
9696
</Text>
9797
)
9898
}
99+
removeClippedSubviews
99100
/>
100101
)
101102
}

src/components/Artists/component.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ export default function Artists({
168168
if (artistsInfiniteQuery.hasNextPage && !artistsInfiniteQuery.isFetching)
169169
artistsInfiniteQuery.fetchNextPage()
170170
}}
171-
removeClippedSubviews
172171
/>
173172

174173
{showAlphabeticalSelector && artistPageParams && (

src/components/Context/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function AddToPlaylistRow({ track }: { track: BaseItemDto }): React.JSX.Element
137137
}}
138138
pressStyle={{ opacity: 0.5 }}
139139
>
140-
<Icon color='$primary' name='playlist-plus' />
140+
<Icon small color='$primary' name='playlist-plus' />
141141

142142
<Text bold>Add to Playlist</Text>
143143
</ListItem>
@@ -164,9 +164,11 @@ function AddToQueueMenuRow({ tracks }: { tracks: BaseItemDto[] }): React.JSX.Ele
164164
}}
165165
pressStyle={{ opacity: 0.5 }}
166166
>
167-
<Icon color='$primary' name='music-note-plus' />
167+
<Icon small color='$primary' name='music-note-plus' />
168168

169-
<Text bold>Add to Queue</Text>
169+
<Text bold marginLeft={'$1'}>
170+
Add to Queue
171+
</Text>
170172
</ListItem>
171173
)
172174
}
@@ -206,7 +208,7 @@ function ViewAlbumMenuRow({ album: album, stackNavigation }: MenuRowProps): Reac
206208
onPress={goToAlbum}
207209
pressStyle={{ opacity: 0.5 }}
208210
>
209-
<ItemImage item={album} height={'$10'} width={'$10'} />
211+
<ItemImage item={album} height={'$9'} width={'$9'} />
210212

211213
<TextTicker {...TextTickerConfig}>
212214
<Text bold>{`Go to ${getItemName(album)}`}</Text>
@@ -263,7 +265,7 @@ function ViewArtistMenuRow({
263265
onPress={() => goToArtist(artist)}
264266
pressStyle={{ opacity: 0.5 }}
265267
>
266-
<ItemImage circular item={artist} height={'$10'} width={'$10'} />
268+
<ItemImage circular item={artist} height={'$9'} width={'$9'} />
267269

268270
<Text bold>{`Go to ${getItemName(artist)}`}</Text>
269271
</ListItem>

src/components/Global/components/favorite-context-menu-row.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ export default function FavoriteContextMenuRow({ item }: { item: BaseItemDto }):
7272
pressStyle={{ opacity: 0.5 }}
7373
>
7474
<Animated.View entering={FadeIn} exiting={FadeOut} key={`${item.Id}-favorite-row`}>
75-
<XStack alignContent='center' justifyContent='flex-start' gap={'$3'}>
76-
<Icon name={'heart-outline'} small color={'$primary'} />
75+
<XStack alignItems='center' justifyContent='flex-start' gap={'$2'}>
76+
<Icon small name={'heart-outline'} color={'$primary'} />
7777

78-
<Text marginTop={'$2'} bold>
79-
Add to favorites
80-
</Text>
78+
<Text bold>Add to favorites</Text>
8179
</XStack>
8280
</Animated.View>
8381
</ListItem>

src/components/Global/components/icon.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default function Icon({
4949
onPress={onPress}
5050
onPressIn={onPressIn}
5151
hitSlop={getTokenValue('$2.5')}
52+
marginHorizontal={'$1'}
5253
width={size}
5354
height={size}
5455
flex={flex}

src/components/Global/components/track.tsx

Lines changed: 67 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import navigationRef from '../../../../navigation'
2424
import { NativeStackNavigationProp } from '@react-navigation/native-stack'
2525
import { BaseStackParamList } from '../../../screens/types'
2626
import { fetchItem } from '../../../api/queries/item'
27+
import ItemImage from './image'
28+
import { ItemProvider } from '../../../providers/Item'
2729

2830
export interface TrackProps {
2931
track: BaseItemDto
@@ -84,21 +86,6 @@ export default function Track({
8486
[networkStatus],
8587
)
8688

87-
// Memoize image source to prevent recreation
88-
const imageSource = useMemo(
89-
() => ({
90-
uri:
91-
getImageApi(api!).getItemImageUrlById(
92-
track.AlbumId! || track.Id!,
93-
ImageType.Primary,
94-
{
95-
tag: track.ImageTags?.Primary,
96-
},
97-
) || '',
98-
}),
99-
[api, track.AlbumId, track.Id, track.ImageTags?.Primary],
100-
)
101-
10289
// Memoize tracklist for queue loading
10390
const memoizedTracklist = useMemo(
10491
() => tracklist ?? playQueue.map((track) => track.item),
@@ -188,91 +175,85 @@ export default function Track({
188175
)
189176

190177
return (
191-
<Theme name={invertedColors ? 'inverted_purple' : undefined}>
192-
<XStack
193-
alignContent='center'
194-
alignItems='center'
195-
height={showArtwork ? '$6' : '$5'}
196-
flex={1}
197-
testID={testID ?? undefined}
198-
onPress={handlePress}
199-
onLongPress={handleLongPress}
200-
paddingVertical={'$2'}
201-
justifyContent='center'
202-
marginRight={'$2'}
203-
>
178+
<ItemProvider item={track}>
179+
<Theme name={invertedColors ? 'inverted_purple' : undefined}>
204180
<XStack
205181
alignContent='center'
182+
alignItems='center'
183+
height={showArtwork ? '$6' : '$5'}
184+
flex={1}
185+
testID={testID ?? undefined}
186+
onPress={handlePress}
187+
onLongPress={handleLongPress}
188+
paddingVertical={'$2'}
206189
justifyContent='center'
207-
marginHorizontal={showArtwork ? '$2' : '$1'}
190+
marginRight={'$2'}
208191
>
209-
{showArtwork ? (
210-
<FastImage
211-
key={`${track.Id}-${track.AlbumId || track.Id}`}
212-
source={imageSource}
213-
style={{
214-
width: getToken('$12'),
215-
height: getToken('$12'),
216-
borderRadius: getToken('$1'),
217-
}}
218-
/>
219-
) : (
220-
<Text
221-
key={`${track.Id}-number`}
222-
color={textColor}
223-
width={getToken('$12')}
224-
textAlign='center'
225-
>
226-
{indexNumber}
227-
</Text>
228-
)}
229-
</XStack>
230-
231-
<YStack alignContent='center' justifyContent='flex-start' flex={6}>
232-
<Text
233-
key={`${track.Id}-name`}
234-
bold
235-
color={textColor}
236-
lineBreakStrategyIOS='standard'
237-
numberOfLines={1}
192+
<XStack
193+
alignContent='center'
194+
justifyContent='center'
195+
marginHorizontal={showArtwork ? '$2' : '$1'}
238196
>
239-
{trackName}
240-
</Text>
197+
{showArtwork ? (
198+
<ItemImage item={track} width={'$12'} height={'$12'} />
199+
) : (
200+
<Text
201+
key={`${track.Id}-number`}
202+
color={textColor}
203+
width={getToken('$12')}
204+
textAlign='center'
205+
>
206+
{indexNumber}
207+
</Text>
208+
)}
209+
</XStack>
241210

242-
{shouldShowArtists && (
211+
<YStack alignContent='center' justifyContent='flex-start' flex={6}>
243212
<Text
244-
key={`${track.Id}-artists`}
213+
key={`${track.Id}-name`}
214+
bold
215+
color={textColor}
245216
lineBreakStrategyIOS='standard'
246217
numberOfLines={1}
247218
>
248-
{artistsText}
219+
{trackName}
249220
</Text>
250-
)}
251-
</YStack>
252221

253-
<DownloadedIcon item={track} />
222+
{shouldShowArtists && (
223+
<Text
224+
key={`${track.Id}-artists`}
225+
lineBreakStrategyIOS='standard'
226+
numberOfLines={1}
227+
>
228+
{artistsText}
229+
</Text>
230+
)}
231+
</YStack>
254232

255-
<FavoriteIcon item={track} />
233+
<DownloadedIcon item={track} />
256234

257-
<RunTimeTicks
258-
key={`${track.Id}-runtime`}
259-
props={{
260-
style: {
261-
textAlign: 'center',
262-
flex: 1.5,
263-
alignSelf: 'center',
264-
},
265-
}}
266-
>
267-
{track.RunTimeTicks}
268-
</RunTimeTicks>
235+
<FavoriteIcon item={track} />
269236

270-
<Icon
271-
name={showRemove ? 'close' : 'dots-horizontal'}
272-
flex={1}
273-
onPress={handleIconPress}
274-
/>
275-
</XStack>
276-
</Theme>
237+
<RunTimeTicks
238+
key={`${track.Id}-runtime`}
239+
props={{
240+
style: {
241+
textAlign: 'center',
242+
flex: 1.5,
243+
alignSelf: 'center',
244+
},
245+
}}
246+
>
247+
{track.RunTimeTicks}
248+
</RunTimeTicks>
249+
250+
<Icon
251+
name={showRemove ? 'close' : 'dots-horizontal'}
252+
flex={1}
253+
onPress={handleIconPress}
254+
/>
255+
</XStack>
256+
</Theme>
257+
</ItemProvider>
277258
)
278259
}

0 commit comments

Comments
 (0)