mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
fix nav and folder banner text responsiveness
This commit is contained in:
+32
-6
@@ -12,10 +12,7 @@ import {
|
||||
Track,
|
||||
} from "../interfaces";
|
||||
|
||||
function writeQueue(
|
||||
from: fromFolder | fromAlbum | fromPlaylist,
|
||||
tracks: Track[]
|
||||
) {
|
||||
function writeQueue(from: From, tracks: Track[]) {
|
||||
localStorage.setItem(
|
||||
"queue",
|
||||
JSON.stringify({
|
||||
@@ -46,6 +43,15 @@ const defaultTrack = <Track>{
|
||||
image: "meh",
|
||||
};
|
||||
|
||||
function shuffle(tracks: Track[]) {
|
||||
const shuffled = tracks.slice();
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||
}
|
||||
return shuffled;
|
||||
}
|
||||
|
||||
type From = fromFolder | fromAlbum | fromPlaylist | fromSearch;
|
||||
|
||||
export default defineStore("Queue", {
|
||||
@@ -76,7 +82,7 @@ export default defineStore("Queue", {
|
||||
const track = this.tracklist[index];
|
||||
this.currentid = track.trackid;
|
||||
const uri = state.settings.uri + "/file/" + track.trackid;
|
||||
const elem = document.getElementById("progress");
|
||||
const elem = document.getElementById("progress") as HTMLElement;
|
||||
this.updateCurrent(index);
|
||||
|
||||
new Promise((resolve, reject) => {
|
||||
@@ -173,7 +179,7 @@ export default defineStore("Queue", {
|
||||
this.currenttrack = track;
|
||||
this.current = index;
|
||||
this.currentid = track.trackid;
|
||||
this.duration.full = track.length;
|
||||
this.duration.full = track.length || 0;
|
||||
},
|
||||
setNewQueue(tracklist: Track[]) {
|
||||
if (this.tracklist !== tracklist) {
|
||||
@@ -260,5 +266,25 @@ export default defineStore("Queue", {
|
||||
writeQueue(this.from, [defaultTrack] as Track[]);
|
||||
writeCurrent(0);
|
||||
},
|
||||
shuffleQueue() {
|
||||
const Toast = useNotifStore();
|
||||
if (this.tracklist.length < 2) {
|
||||
Toast.showNotification("Queue is too short", NotifType.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
const shuffled = shuffle(this.tracklist);
|
||||
this.tracklist = shuffled;
|
||||
|
||||
this.current = 0;
|
||||
this.play(this.current);
|
||||
|
||||
this.currentid = shuffled[0].trackid;
|
||||
this.next = 1;
|
||||
this.prev = this.tracklist.length - 1;
|
||||
|
||||
writeQueue(this.from, shuffled);
|
||||
writeCurrent(0);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user