mirror of
https://github.com/anultravioletaurora/Jellify.git
synced 2025-12-16 18:55:44 -06:00
cleaning up loadQueue function
Removing the need for a "downloadedTracks" parameter and instead just fetching from the audiocache fix carplay not showing up
This commit is contained in:
@@ -77,6 +77,7 @@ function App(): React.JSX.Element {
|
||||
|
||||
return (
|
||||
<NetworkContextProvider>
|
||||
<CarPlayProvider />
|
||||
<PlayerProvider />
|
||||
<Root />
|
||||
<Toast topOffset={getToken('$12')} config={JellifyToastConfig(theme)} />
|
||||
|
||||
@@ -9,10 +9,7 @@ import JellifyTrack from '../../../types/JellifyTrack'
|
||||
import { getCurrentTrack } from '.'
|
||||
import { JellifyDownload } from '../../../types/JellifyDownload'
|
||||
import { usePlayerQueueStore } from '../../../stores/player/queue'
|
||||
|
||||
type LoadQueueOperation = QueueMutation & {
|
||||
downloadedTracks: JellifyDownload[] | undefined
|
||||
}
|
||||
import { getAudioCache } from '../../../api/mutations/download/offlineModeUtils'
|
||||
|
||||
type LoadQueueResult = {
|
||||
finalStartIndex: number
|
||||
@@ -27,8 +24,7 @@ export async function loadQueue({
|
||||
api,
|
||||
deviceProfile,
|
||||
networkStatus = networkStatusTypes.ONLINE,
|
||||
downloadedTracks,
|
||||
}: LoadQueueOperation): Promise<LoadQueueResult> {
|
||||
}: QueueMutation): Promise<LoadQueueResult> {
|
||||
usePlayerQueueStore.getState().setQueueRef(queueRef)
|
||||
usePlayerQueueStore.getState().setShuffled(shuffled)
|
||||
|
||||
@@ -37,6 +33,8 @@ export async function loadQueue({
|
||||
// Get the item at the start index
|
||||
const startingTrack = tracklist[startIndex]
|
||||
|
||||
const downloadedTracks = getAudioCache()
|
||||
|
||||
const availableAudioItems = filterTracksOnNetworkStatus(
|
||||
networkStatus as networkStatusTypes,
|
||||
tracklist,
|
||||
|
||||
@@ -14,12 +14,12 @@ import { useRemoteMediaClient } from 'react-native-google-cast'
|
||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack'
|
||||
import { RootStackParamList } from '../../../screens/types'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
import { useAllDownloadedTracks } from '../../../api/queries/download'
|
||||
import useHapticFeedback from '../../../hooks/use-haptic-feedback'
|
||||
import { queryClient } from '../../../constants/query-client'
|
||||
import { REPEAT_MODE_QUERY_KEY } from '../constants/query-keys'
|
||||
import { usePlayerQueueStore } from '../../../stores/player/queue'
|
||||
import { useCallback } from 'react'
|
||||
import { getAudioCache } from '../../../api/mutations/download/offlineModeUtils'
|
||||
|
||||
/**
|
||||
* A mutation to handle starting playback
|
||||
@@ -151,15 +151,13 @@ const useSeekBy = () => {
|
||||
}
|
||||
|
||||
export const useAddToQueue = () => {
|
||||
const downloadedTracks = useAllDownloadedTracks().data
|
||||
|
||||
const trigger = useHapticFeedback()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (variables: AddToQueueMutation) =>
|
||||
variables.queuingType === QueuingType.PlayingNext
|
||||
? playNextInQueue({ ...variables, downloadedTracks })
|
||||
: playLaterInQueue({ ...variables, downloadedTracks }),
|
||||
? playNextInQueue({ ...variables, downloadedTracks: getAudioCache() })
|
||||
: playLaterInQueue({ ...variables, downloadedTracks: getAudioCache() }),
|
||||
onSuccess: (_: void, { queuingType }: AddToQueueMutation) => {
|
||||
trigger('notificationSuccess')
|
||||
console.debug(
|
||||
@@ -198,15 +196,13 @@ export const useLoadNewQueue = () => {
|
||||
const remoteClient = useRemoteMediaClient()
|
||||
const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>()
|
||||
|
||||
const { data: downloadedTracks } = useAllDownloadedTracks()
|
||||
|
||||
const trigger = useHapticFeedback()
|
||||
|
||||
return useCallback(
|
||||
async (variables: QueueMutation) => {
|
||||
trigger('impactLight')
|
||||
await TrackPlayer.pause()
|
||||
const { finalStartIndex, tracks } = await loadQueue({ ...variables, downloadedTracks })
|
||||
const { finalStartIndex, tracks } = await loadQueue({ ...variables })
|
||||
|
||||
usePlayerQueueStore.getState().setCurrentIndex(finalStartIndex)
|
||||
|
||||
@@ -225,7 +221,7 @@ export const useLoadNewQueue = () => {
|
||||
usePlayerQueueStore.getState().setQueue(tracks)
|
||||
usePlayerQueueStore.getState().setCurrentTrack(tracks[finalStartIndex])
|
||||
},
|
||||
[isCasting, remoteClient, navigation, downloadedTracks, trigger, usePlayerQueueStore],
|
||||
[isCasting, remoteClient, navigation, trigger, usePlayerQueueStore],
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user