Support for add items in custom position

This commit is contained in:
SrGooglo 2025-02-05 02:33:54 +00:00
parent 8aa6913b72
commit c3df679449

View File

@ -20,7 +20,9 @@ export default class QueueManager {
} }
if (random) { if (random) {
const randomIndex = Math.floor(Math.random() * this.nextItems.length) const randomIndex = Math.floor(
Math.random() * this.nextItems.length,
)
this.currentItem = this.nextItems.splice(randomIndex, 1)[0] this.currentItem = this.nextItems.splice(randomIndex, 1)[0]
} else { } else {
@ -83,12 +85,16 @@ export default class QueueManager {
return this.currentItem return this.currentItem
} }
add = (items) => { add = (items, position = "end") => {
if (!Array.isArray(items)) { if (!Array.isArray(items)) {
items = [items] items = [items]
} }
if (position === "start") {
this.nextItems = [...items, ...this.nextItems]
} else {
this.nextItems = [...this.nextItems, ...items] this.nextItems = [...this.nextItems, ...items]
}
return items return items
} }