From 527051f8a25ea4d1b5b2686cabd3ea9065eec8a2 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Sat, 10 Sep 2022 20:32:17 +0300 Subject: [PATCH] maintain playing track on shuffle (when audio is playing) --- src/components/nav/NavBar.vue | 14 -------------- src/components/nav/Titles/QueueTitle.vue | 2 +- src/stores/queue.ts | 22 +++++++++++++++++----- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/components/nav/NavBar.vue b/src/components/nav/NavBar.vue index 18659e5d..5d3ecbb4 100644 --- a/src/components/nav/NavBar.vue +++ b/src/components/nav/NavBar.vue @@ -4,9 +4,6 @@
- @@ -39,7 +32,6 @@ import { Routes } from "@/composables/enums"; import NavButtons from "./NavButtons.vue"; import FolderTitle from "./Titles/Folder.vue"; -import SimpleTitle from "./Titles/SimpleTitle.vue"; import APTitle from "./Titles/APTitle.vue"; import SearchTitle from "./Titles/SearchTitle.vue"; import PlaylistsTitle from "./Titles/PlaylistsTitle.vue"; @@ -51,12 +43,6 @@ const nav = useNavStore(); const subPaths = ref([]); -function hideOverflow() { - const { name } = route; - const { album, playlist, search, folder } = Routes; - - return (album + playlist + search + folder).includes(name as string); -} watch( () => route.name, diff --git a/src/components/nav/Titles/QueueTitle.vue b/src/components/nav/Titles/QueueTitle.vue index 7152e15c..c504073c 100644 --- a/src/components/nav/Titles/QueueTitle.vue +++ b/src/components/nav/Titles/QueueTitle.vue @@ -6,7 +6,7 @@
- + {{ name }}
diff --git a/src/stores/queue.ts b/src/stores/queue.ts index 2e04201f..98783d56 100644 --- a/src/stores/queue.ts +++ b/src/stores/queue.ts @@ -204,15 +204,27 @@ export default defineStore("Queue", { return; } - const shuffled = shuffle(this.tracklist); - this.tracklist = shuffled; + const current = this.currenttrack; + const current_hash = current.hash; - this.currentindex = 0; - this.currentid = shuffled[0].trackid; + this.tracklist = shuffle(this.tracklist); + // find current track after shuffle if (this.playing) { - this.play(this.currentindex); + const newindex = this.tracklist.findIndex( + (track) => track.hash === current_hash + ); + + // remove current track from queue + this.tracklist.splice(newindex, 1); + // insert current track at beginning of queue + this.tracklist.unshift(current); + this.currentindex = 0; + return; } + + this.currentindex = 0; + this.play(this.currentindex); }, removeFromQueue(index: number = 0) { this.tracklist.splice(index, 1);