Skip to content

Commit

Permalink
Respect autostartVideoOnPlaySelected in scene queue
Browse files Browse the repository at this point in the history
  • Loading branch information
DingDongSoLong4 committed Jan 3, 2024
1 parent 53c58d1 commit 38c7056
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
87 changes: 47 additions & 40 deletions ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -104,9 +104,9 @@ const ScenePage: React.FC<IProps> = ({
onQueueNext,
onQueuePrevious,
onQueueRandom,
onQueueSceneClicked,
onDelete,
continuePlaylist,
loadScene,
queueHasMoreScenes,
onQueueMoreScenes,
onQueueLessScenes,
Expand Down Expand Up @@ -445,7 +445,7 @@ const ScenePage: React.FC<IProps> = ({
currentID={scene.id}
continue={continuePlaylist}
setContinue={setContinuePlaylist}
onSceneClicked={loadScene}
onSceneClicked={onQueueSceneClicked}
onNext={onQueueNext}
onPrevious={onQueuePrevious}
onRandom={onQueueRandom}
Expand Down Expand Up @@ -594,6 +594,9 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
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]
Expand Down Expand Up @@ -692,54 +695,46 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
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);
Expand All @@ -753,18 +748,30 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
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");
}
}

Expand All @@ -780,8 +787,8 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
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) {
Expand All @@ -798,11 +805,11 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
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}
Expand All @@ -820,8 +827,8 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
initialTimestamp={initialTimestamp}
sendSetTimestamp={getSetTimestamp}
onComplete={onComplete}
onNext={onQueueNext}
onPrevious={onQueuePrevious}
onNext={() => queueNext(true)}
onPrevious={() => queuePrevious(true)}
/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions ui/v2.5/src/models/sceneQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 38c7056

Please sign in to comment.