Kasper Seweryn 2023-01-28 23:45:15 +01:00 committed by Marge
parent 026196d698
commit d3b3463415
2 changed files with 13 additions and 5 deletions

View File

@ -174,7 +174,12 @@ export const useQueue = createGlobalState(() => {
await playNext(true)
}
tracks.value.splice(index, 1)
if (isShuffled.value) {
tracks.value.splice(tracks.value.indexOf(shuffledIds.value[index]), 1)
shuffledIds.value.splice(index, 1)
} else {
tracks.value.splice(index, 1)
}
if (index <= currentIndex.value) {
currentIndex.value -= 1
@ -239,8 +244,12 @@ export const useQueue = createGlobalState(() => {
// Reorder
const reorder = (from: number, to: number) => {
const [id] = tracks.value.splice(from, 1)
tracks.value.splice(to, 0, id)
const list = isShuffled.value
? shuffledIds
: tracks
const [id] = list.value.splice(from, 1)
list.value.splice(to, 0, id)
const current = currentIndex.value
if (current === from) {

View File

@ -111,7 +111,6 @@ export const useTracks = createGlobalState(() => {
// Preload next track
const { start: startPreloadTimeout } = useTimeoutFn(async (index) => {
console.log('@@@@', index)
const { queue } = useQueue()
const sound = await createSound(queue.value[index as number])
await sound.preload()
@ -170,7 +169,7 @@ export const useTracks = createGlobalState(() => {
// NOTE: Preload next track
// Calling this function clears previous timeout and starts a new one.
// Since this watchEffect fires whenever currentIndex / nextTrack changes, it will automatically cleanup previous preload.
// @ts-expect-error vueuse is wrongly typed?
// @ts-expect-error vueuse is wrongly typed: https://github.com/vueuse/vueuse/issues/2691
startPreloadTimeout(currentIndex.value + 1)
})