From 38c70569e94704ae792414e8faab37f82e6ab5cc Mon Sep 17 00:00:00 2001 From: DingDongSoLong4 <99329275+DingDongSoLong4@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:17:02 +0200 Subject: [PATCH] Respect autostartVideoOnPlaySelected in scene queue --- .../components/Scenes/SceneDetails/Scene.tsx | 87 ++++++++++--------- ui/v2.5/src/models/sceneQueue.ts | 4 +- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx b/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx index eb3cbcb48db..10637f35f2a 100644 --- a/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx +++ b/ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx @@ -81,9 +81,9 @@ interface IProps { onQueueNext: () => void; onQueuePrevious: () => void; onQueueRandom: () => void; + onQueueSceneClicked: (sceneID: string) => void; onDelete: () => void; continuePlaylist: boolean; - loadScene: (sceneID: string) => void; queueHasMoreScenes: boolean; onQueueMoreScenes: () => void; onQueueLessScenes: () => void; @@ -104,9 +104,9 @@ const ScenePage: React.FC = ({ onQueueNext, onQueuePrevious, onQueueRandom, + onQueueSceneClicked, onDelete, continuePlaylist, - loadScene, queueHasMoreScenes, onQueueMoreScenes, onQueueLessScenes, @@ -445,7 +445,7 @@ const ScenePage: React.FC = ({ currentID={scene.id} continue={continuePlaylist} setContinue={setContinuePlaylist} - onSceneClicked={loadScene} + onSceneClicked={onQueueSceneClicked} onNext={onQueueNext} onPrevious={onQueuePrevious} onRandom={onQueueRandom} @@ -594,6 +594,9 @@ const SceneLoader: React.FC> = ({ const [queueStart, setQueueStart] = useState(1); const autoplay = queryParams.get("autoplay") === "true"; + const autoPlayOnSelected = + configuration?.interface.autostartVideoOnPlaySelected ?? false; + const currentQueueIndex = useMemo( () => queueScenes.findIndex((s) => s.id === id), [queueScenes, id] @@ -692,54 +695,46 @@ const SceneLoader: React.FC> = ({ history.replace(sceneLink); } - function onDelete() { - if ( - continuePlaylist && - currentQueueIndex >= 0 && - currentQueueIndex < queueScenes.length - 1 - ) { - loadScene(queueScenes[currentQueueIndex + 1].id); - } else { - history.push("/scenes"); - } - } + async function queueNext(autoPlay: boolean) { + if (currentQueueIndex === -1) return; - async function onQueueNext() { - if (currentQueueIndex >= 0 && currentQueueIndex < queueScenes.length - 1) { - loadScene(queueScenes[currentQueueIndex + 1].id, true); + if (currentQueueIndex < queueScenes.length - 1) { + loadScene(queueScenes[currentQueueIndex + 1].id, autoPlay); } else { // if we're at the end of the queue, load more scenes - if ( - currentQueueIndex >= 0 && - currentQueueIndex === queueScenes.length - 1 && - queueHasMoreScenes - ) { + if (currentQueueIndex === queueScenes.length - 1 && queueHasMoreScenes) { const loadedScenes = await onQueueMoreScenes(); if (loadedScenes && loadedScenes.length > 0) { // set the page to the next page const newPage = (sceneQueue.query?.currentPage ?? 0) + 1; - loadScene(loadedScenes[0].id, true, newPage); + loadScene(loadedScenes[0].id, autoPlay, newPage); } } } } - async function onQueuePrevious() { + async function queuePrevious(autoPlay: boolean) { + if (currentQueueIndex === -1) return; + if (currentQueueIndex > 0) { - loadScene(queueScenes[currentQueueIndex - 1].id, true); + loadScene(queueScenes[currentQueueIndex - 1].id, autoPlay); } else { // if we're at the beginning of the queue, load the previous page - if (currentQueueIndex === 0 && queueStart > 1) { + if (queueStart > 1) { const loadedScenes = await onQueueLessScenes(); if (loadedScenes && loadedScenes.length > 0) { const newPage = (sceneQueue.query?.currentPage ?? 0) - 1; - loadScene(loadedScenes[loadedScenes.length - 1].id, true, newPage); + loadScene( + loadedScenes[loadedScenes.length - 1].id, + autoPlay, + newPage + ); } } } } - async function onQueueRandom() { + async function queueRandom(autoPlay: boolean) { if (sceneQueue.query) { const { query } = sceneQueue; const pages = Math.ceil(queueTotal / query.itemsPerPage); @@ -753,18 +748,30 @@ const SceneLoader: React.FC> = ({ if (queryResults.data.findScenes.scenes.length > index) { const { id: sceneID } = queryResults.data.findScenes.scenes[index]; // navigate to the image player page - loadScene(sceneID, undefined, page); + loadScene(sceneID, autoPlay, page); } - } else { + } else if (queueTotal !== 0) { const index = Math.floor(Math.random() * queueTotal); - loadScene(queueScenes[index].id); + loadScene(queueScenes[index].id, autoPlay); } } function onComplete() { // load the next scene if we're continuing if (continuePlaylist) { - onQueueNext(); + queueNext(true); + } + } + + function onDelete() { + if ( + continuePlaylist && + currentQueueIndex >= 0 && + currentQueueIndex < queueScenes.length - 1 + ) { + loadScene(queueScenes[currentQueueIndex + 1].id); + } else { + history.push("/scenes"); } } @@ -780,8 +787,8 @@ const SceneLoader: React.FC> = ({ return Math.floor((index + queueStart - 1) / perPage) + 1; } - function onSceneClicked(sceneID: string) { - loadScene(sceneID, true, getScenePage(sceneID)); + function onQueueSceneClicked(sceneID: string) { + loadScene(sceneID, autoPlayOnSelected, getScenePage(sceneID)); } if (!scene) { @@ -798,11 +805,11 @@ const SceneLoader: React.FC> = ({ queueScenes={queueScenes} queueStart={queueStart} onDelete={onDelete} - onQueueNext={onQueueNext} - onQueuePrevious={onQueuePrevious} - onQueueRandom={onQueueRandom} + onQueueNext={() => queueNext(autoPlayOnSelected)} + onQueuePrevious={() => queuePrevious(autoPlayOnSelected)} + onQueueRandom={() => queueRandom(autoPlayOnSelected)} + onQueueSceneClicked={onQueueSceneClicked} continuePlaylist={continuePlaylist} - loadScene={onSceneClicked} queueHasMoreScenes={queueHasMoreScenes} onQueueLessScenes={onQueueLessScenes} onQueueMoreScenes={onQueueMoreScenes} @@ -820,8 +827,8 @@ const SceneLoader: React.FC> = ({ initialTimestamp={initialTimestamp} sendSetTimestamp={getSetTimestamp} onComplete={onComplete} - onNext={onQueueNext} - onPrevious={onQueuePrevious} + onNext={() => queueNext(true)} + onPrevious={() => queuePrevious(true)} /> diff --git a/ui/v2.5/src/models/sceneQueue.ts b/ui/v2.5/src/models/sceneQueue.ts index 14f81df5925..79332edc4e1 100644 --- a/ui/v2.5/src/models/sceneQueue.ts +++ b/ui/v2.5/src/models/sceneQueue.ts @@ -112,8 +112,8 @@ export class SceneQueue { let params = [ this.makeQueryParameters(options.sceneIndex, options.newPage), ]; - if (options.autoPlay !== undefined) { - params.push("autoplay=" + options.autoPlay); + if (options.autoPlay) { + params.push("autoplay=true"); } if (options.continue !== undefined) { params.push("continue=" + options.continue);