From f5552a4cc36ed5945a220dac65fb8d53a2bc3a85 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Thu, 21 Jul 2022 19:03:26 +0200 Subject: [PATCH] Fix audio playlist order --- src/components/appMediaPlaybackController.ts | 32 ++++++++++++-------- src/helpers/searchListLoader.ts | 8 ++--- src/scss/partials/_ckin.scss | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/components/appMediaPlaybackController.ts b/src/components/appMediaPlaybackController.ts index 2ffe5f26..64126732 100644 --- a/src/components/appMediaPlaybackController.ts +++ b/src/components/appMediaPlaybackController.ts @@ -584,23 +584,29 @@ export class AppMediaPlaybackController extends EventListenerBase<{ const listLoader = this.listLoader; const current = listLoader.getCurrent(); if(!current || !verify(current)) { - const previous = listLoader.getPrevious(); - - let idx = previous.findIndex(verify); let jumpLength: number; - if(idx !== -1) { - jumpLength = -(previous.length - idx); - } else { - idx = listLoader.getNext().findIndex(verify); + + for(const withOtherSide of [false, true]) { + const previous = listLoader.getPrevious(withOtherSide); + + let idx = previous.findIndex(verify); if(idx !== -1) { - jumpLength = idx + 1; + jumpLength = -(previous.length - idx); + } else { + const next = listLoader.getNext(withOtherSide); + idx = next.findIndex(verify); + if(idx !== -1) { + jumpLength = idx + 1; + } + } + + if(jumpLength !== undefined) { + break; } } - if(idx !== -1) { - if(jumpLength) { - this.go(jumpLength, false); - } + if(jumpLength) { + this.go(jumpLength, false); } else { this.setTargets({peerId, mid}); } @@ -645,7 +651,7 @@ export class AppMediaPlaybackController extends EventListenerBase<{ const listLoader = this.listLoader; if(this.lockedSwitchers || (!this.round && listLoader.current && !listLoader.next.length) || - !listLoader.getNext().length || + !listLoader.getNext(true).length || !this.next()) { this.stop(); this.dispatchEvent('stop'); diff --git a/src/helpers/searchListLoader.ts b/src/helpers/searchListLoader.ts index 54b41f2a..11b86f7d 100644 --- a/src/helpers/searchListLoader.ts +++ b/src/helpers/searchListLoader.ts @@ -191,20 +191,20 @@ export default class SearchListLoader