@@ -1,7 +1,7 @@
|
|||||||
import React, { PropsWithChildren, useCallback } from 'react';
|
import React, { PropsWithChildren, useCallback } from 'react';
|
||||||
import { Pressable, ViewStyle } from 'react-native';
|
import { Pressable, ViewStyle } from 'react-native';
|
||||||
|
|
||||||
interface TouchableHandlerProps<T = number> {
|
interface TouchableHandlerProps<T> {
|
||||||
id: T;
|
id: T;
|
||||||
onPress: (id: T) => void;
|
onPress: (id: T) => void;
|
||||||
onLongPress?: (id: T) => void;
|
onLongPress?: (id: T) => void;
|
||||||
|
|||||||
@@ -148,12 +148,15 @@ const TrackListView: React.FC<TrackListViewProps> = ({
|
|||||||
// Setup callbacks
|
// Setup callbacks
|
||||||
const playEntity = useCallback(() => { playTracks(trackIds); }, [playTracks, trackIds]);
|
const playEntity = useCallback(() => { playTracks(trackIds); }, [playTracks, trackIds]);
|
||||||
const shuffleEntity = useCallback(() => { playTracks(trackIds, { shuffle: true }); }, [playTracks, trackIds]);
|
const shuffleEntity = useCallback(() => { playTracks(trackIds, { shuffle: true }); }, [playTracks, trackIds]);
|
||||||
const selectTrack = useCallback(async (index: number) => {
|
const selectTrack = useCallback(async (trackId: string) => {
|
||||||
await playTracks(trackIds, { playIndex: index });
|
const index = trackIds.findIndex((id) => id === trackId);
|
||||||
|
if (index) {
|
||||||
|
await playTracks(trackIds, { playIndex: index });
|
||||||
|
}
|
||||||
}, [playTracks, trackIds]);
|
}, [playTracks, trackIds]);
|
||||||
const longPressTrack = useCallback((index: number) => {
|
const longPressTrack = useCallback((trackId: string) => {
|
||||||
navigation.navigate('TrackPopupMenu', { trackId: trackIds[index].toString() });
|
navigation.navigate('TrackPopupMenu', { trackId });
|
||||||
}, [navigation, trackIds]);
|
}, [navigation]);
|
||||||
const downloadAllTracks = useCallback(() => {
|
const downloadAllTracks = useCallback(() => {
|
||||||
trackIds.forEach((trackId) => dispatch(queueTrackForDownload(trackId)));
|
trackIds.forEach((trackId) => dispatch(queueTrackForDownload(trackId)));
|
||||||
}, [dispatch, trackIds]);
|
}, [dispatch, trackIds]);
|
||||||
@@ -190,7 +193,7 @@ const TrackListView: React.FC<TrackListViewProps> = ({
|
|||||||
{groupTrackIds.map((trackId, i) =>
|
{groupTrackIds.map((trackId, i) =>
|
||||||
<TouchableHandler
|
<TouchableHandler
|
||||||
key={trackId}
|
key={trackId}
|
||||||
id={i}
|
id={trackId}
|
||||||
onPress={selectTrack}
|
onPress={selectTrack}
|
||||||
onLongPress={longPressTrack}
|
onLongPress={longPressTrack}
|
||||||
testID={`play-track-${trackId}`}
|
testID={`play-track-${trackId}`}
|
||||||
|
|||||||
Reference in New Issue
Block a user