feat(PlayQueueItem): add moveUp and moveDown functions for queue item repositioning

This commit is contained in:
Astrian Zheng 2025-05-27 21:17:37 +10:00
parent cf158c5d73
commit 404698bfd1
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -18,6 +18,79 @@ const playQueueStore = usePlayQueueStore()
const hover = ref(false)
function moveUp() {
if (props.index === 0) return
playQueueStore.queueReplaceLock = true
const queue = [...playQueueStore.list]
if (!playQueueStore.playMode.shuffle) {
// shuffle
const temp = queue[props.index]
queue[props.index] = queue[props.index - 1]
queue[props.index - 1] = temp
playQueueStore.list = queue
// currentIndex
if (props.index === playQueueStore.currentIndex) {
playQueueStore.currentIndex--
} else if (props.index - 1 === playQueueStore.currentIndex) {
playQueueStore.currentIndex++
}
} else {
// Shuffleshuffle
const shuffleList = [...playQueueStore.shuffleList]
const temp = shuffleList[props.index]
shuffleList[props.index] = shuffleList[props.index - 1]
shuffleList[props.index - 1] = temp
playQueueStore.shuffleList = shuffleList
// currentIndex
if (props.index === playQueueStore.currentIndex) {
playQueueStore.currentIndex--
} else if (props.index - 1 === playQueueStore.currentIndex) {
playQueueStore.currentIndex++
}
}
}
function moveDown() {
const listLength = playQueueStore.playMode.shuffle ? playQueueStore.shuffleList.length : playQueueStore.list.length
if (props.index === listLength - 1) return
playQueueStore.queueReplaceLock = true
const queue = [...playQueueStore.list]
if (!playQueueStore.playMode.shuffle) {
// shuffle
const temp = queue[props.index]
queue[props.index] = queue[props.index + 1]
queue[props.index + 1] = temp
playQueueStore.list = queue
// currentIndex
if (props.index === playQueueStore.currentIndex) {
playQueueStore.currentIndex++
} else if (props.index + 1 === playQueueStore.currentIndex) {
playQueueStore.currentIndex--
}
} else {
// Shuffleshuffle
const shuffleList = [...playQueueStore.shuffleList]
const temp = shuffleList[props.index]
shuffleList[props.index] = shuffleList[props.index + 1]
shuffleList[props.index + 1] = temp
playQueueStore.shuffleList = shuffleList
// currentIndex
if (props.index === playQueueStore.currentIndex) {
playQueueStore.currentIndex++
} else if (props.index + 1 === playQueueStore.currentIndex) {
playQueueStore.currentIndex--
}
}
}
function removeItem() {
playQueueStore.queueReplaceLock = true
@ -103,13 +176,15 @@ function removeItem() {
<div class="flex gap-1" v-if="hover">
<button
class="text-white/90 w-4 h-4 hover:scale-110 hover:text-white active:scale-95 active:text-white/85 transition-all"
@click.stop>
@click.stop="moveUp" :disabled="index === 0" v-if="index !== 0">
<UpHyphenIcon :size="4" />
</button>
<button
class="text-white/90 w-4 h-4 hover:scale-110 hover:text-white active:scale-95 active:text-white/85 transition-all"
@click.stop>
@click.stop="moveDown"
:disabled="index === (playQueueStore.playMode.shuffle ? playQueueStore.shuffleList.length : playQueueStore.list.length) - 1"
v-if="index !== (playQueueStore.playMode.shuffle ? playQueueStore.shuffleList.length : playQueueStore.list.length) - 1">
<DownHyphenIcon :size="4" />
</button>