From fd70809e40f691090ee48dc75872866f70cca720 Mon Sep 17 00:00:00 2001 From: Violet Caulfield Date: Wed, 22 Jan 2025 15:38:06 -0600 Subject: [PATCH] Album button changes --- .../ItemDetail/helpers/TrackOptions.tsx | 8 ++--- player/interfaces.ts | 2 ++ player/provider.tsx | 32 ++++++++++++++++--- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/components/ItemDetail/helpers/TrackOptions.tsx b/components/ItemDetail/helpers/TrackOptions.tsx index 9571f8a2..0bb4adf7 100644 --- a/components/ItemDetail/helpers/TrackOptions.tsx +++ b/components/ItemDetail/helpers/TrackOptions.tsx @@ -16,15 +16,15 @@ export default function TrackOptions({ const { data: album, isSuccess } = useItem(item.AlbumId ?? "") return ( - - + { isSuccess && ( { - navigation.navigate("Album", { + navigation.goBack() // Dismiss modal if it exists + navigation.getParent()!.navigate("Album", { album - }) + }); }} /> )} diff --git a/player/interfaces.ts b/player/interfaces.ts index a05c4ba2..31246ff3 100644 --- a/player/interfaces.ts +++ b/player/interfaces.ts @@ -1,3 +1,4 @@ +import { QueuingType } from "../enums/queuing-type"; import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; export interface QueueMutation { @@ -5,4 +6,5 @@ export interface QueueMutation { index?: number | undefined; tracklist: BaseItemDto[]; queueName: string; + queuingType?: QueuingType | undefined; } \ No newline at end of file diff --git a/player/provider.tsx b/player/provider.tsx index c6724dd1..851367ae 100644 --- a/player/provider.tsx +++ b/player/provider.tsx @@ -2,7 +2,7 @@ import { createContext, ReactNode, SetStateAction, useContext, useEffect, useSta import { JellifyTrack } from "../types/JellifyTrack"; import { storage } from "../constants/storage"; import { MMKVStorageKeys } from "../enums/mmkv-storage-keys"; -import { findPlayQueueIndexStart } from "./helpers/index"; +import { findPlayNextIndexStart, findPlayQueueIndexStart } from "./helpers/index"; import TrackPlayer, { Event, Progress, State, usePlaybackState, useProgress, useTrackPlayerEvents } from "react-native-track-player"; import _, { isEqual, isUndefined } from "lodash"; import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api"; @@ -10,13 +10,13 @@ import { handlePlaybackProgressUpdated, handlePlaybackState } from "./handlers"; import { useSetupPlayer, useUpdateOptions } from "../player/hooks"; import { UPDATE_INTERVAL } from "./config"; import { useMutation, UseMutationResult } from "@tanstack/react-query"; -import { QueueMutation } from "./interfaces"; import { mapDtoToTrack } from "../helpers/mappings"; import { QueuingType } from "../enums/queuing-type"; import { trigger } from "react-native-haptic-feedback"; import { getQueue, pause, seekTo, skip, skipToNext, skipToPrevious } from "react-native-track-player/lib/src/trackPlayer"; -import { convertRunTimeTicksToSeconds } from "..//helpers/runtimeticks"; +import { convertRunTimeTicksToSeconds } from "../helpers/runtimeticks"; import Client from "../api/client"; +import { QueueMutation } from "./interfaces"; interface PlayerContext { showPlayer: boolean; @@ -74,7 +74,7 @@ const PlayerContextInitializer = () => { } const addToQueue = async (tracks: JellifyTrack[]) => { - let insertIndex = findPlayQueueIndexStart(queue); + const insertIndex = findPlayQueueIndexStart(queue); console.debug(`Adding ${tracks.length} to queue at index ${insertIndex}`) await TrackPlayer.add(tracks, insertIndex); @@ -83,9 +83,33 @@ const PlayerContextInitializer = () => { setShowMiniplayer(true); } + + const addToNext = async (tracks: JellifyTrack[]) => { + const insertIndex = findPlayNextIndexStart(queue); + + console.debug(`Adding ${tracks.length} to queue at index ${insertIndex}`); + + await TrackPlayer.add(tracks, insertIndex); + + setQueue(await getQueue() as JellifyTrack[]); + + setShowMiniplayer(true); + } //#endregion Functions //#region Hooks + const useQueueMutation = useMutation({ + mutationFn: async (mutation: QueueMutation) => { + trigger("impactLight"); + + if (mutation.queuingType === QueuingType.PlayingNext) + return addToNext([mapDtoToTrack(mutation.track)]); + + else + return addToQueue([mapDtoToTrack(mutation.track)]) + } + }) + const useTogglePlayback = useMutation({ mutationFn: async (index?: number | undefined) => { trigger("impactLight");