mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 13:03:02 +00:00
rewrite sidebar queue using @Akryum/vue-virtual-scroller
This commit is contained in:
committed by
Mungai Njoroge
parent
f0df274b31
commit
858e59f81c
@@ -1,48 +1,47 @@
|
|||||||
<template>
|
<template>
|
||||||
<QueueActions />
|
<QueueActions />
|
||||||
<div
|
<div
|
||||||
ref="scrollable"
|
class="queue-virtual-scroller"
|
||||||
id="queue-scrollable"
|
|
||||||
v-bind="containerProps"
|
|
||||||
style="height: 100%"
|
style="height: 100%"
|
||||||
@mouseover="mouseover = true"
|
@mouseover="mouseover = true"
|
||||||
@mouseout="mouseover = false"
|
@mouseout="mouseover = false"
|
||||||
>
|
>
|
||||||
<div class="inner" v-bind="wrapperProps">
|
<RecycleScroller
|
||||||
|
class="scroller"
|
||||||
|
id="queue-scrollable"
|
||||||
|
:items="scrollerItems"
|
||||||
|
:item-size="itemHeight"
|
||||||
|
key-field="id"
|
||||||
|
v-slot="{ item, index }"
|
||||||
|
>
|
||||||
<TrackItem
|
<TrackItem
|
||||||
style="height: 64px"
|
:track="item.track"
|
||||||
v-for="t in tracks"
|
:isCurrentPlaying="index === queue.currentindex && queue.playing"
|
||||||
:key="t.index"
|
:isCurrent="index === queue.currentindex"
|
||||||
:track="t.data"
|
|
||||||
:index="t.index"
|
|
||||||
:isCurrentPlaying="t.index === queue.currentindex && queue.playing"
|
|
||||||
:isCurrent="t.index === queue.currentindex"
|
|
||||||
:isQueueTrack="true"
|
:isQueueTrack="true"
|
||||||
@PlayThis="playFromQueue(t.index)"
|
@playThis="playFromQueue(index)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</RecycleScroller>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useVirtualList } from "@vueuse/core";
|
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
||||||
|
|
||||||
import useQStore from "@/stores/queue";
|
import useQStore from "@/stores/queue";
|
||||||
|
|
||||||
import TrackItem from "../shared/TrackItem.vue";
|
import TrackItem from "@/components/shared/TrackItem.vue";
|
||||||
import QueueActions from "./Queue/QueueActions.vue";
|
import QueueActions from "./Queue/QueueActions.vue";
|
||||||
|
|
||||||
|
const itemHeight = 64;
|
||||||
const queue = useQStore();
|
const queue = useQStore();
|
||||||
const mouseover = ref(false);
|
const mouseover = ref(false);
|
||||||
const scrollable = ref<HTMLElement>();
|
|
||||||
const sourceTrackList = computed(() => queue.tracklist);
|
const scrollerItems = computed(() => {
|
||||||
const {
|
return queue.tracklist.map((track) => ({
|
||||||
list: tracks,
|
id: Math.random(),
|
||||||
containerProps,
|
track: track,
|
||||||
wrapperProps,
|
}));
|
||||||
} = useVirtualList(sourceTrackList, {
|
|
||||||
itemHeight: 64,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function playFromQueue(index: number) {
|
function playFromQueue(index: number) {
|
||||||
@@ -51,7 +50,6 @@ function playFromQueue(index: number) {
|
|||||||
|
|
||||||
function scrollToCurrent() {
|
function scrollToCurrent() {
|
||||||
const elem = document.getElementById("queue-scrollable") as HTMLElement;
|
const elem = document.getElementById("queue-scrollable") as HTMLElement;
|
||||||
const itemHeight = 64;
|
|
||||||
|
|
||||||
const top = queue.currentindex * itemHeight - itemHeight;
|
const top = queue.currentindex * itemHeight - itemHeight;
|
||||||
elem.scroll({
|
elem.scroll({
|
||||||
@@ -70,12 +68,12 @@ onBeforeUnmount(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.scrollable-r {
|
.queue-virtual-scroller {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: auto;
|
overflow: hidden;
|
||||||
|
|
||||||
.inner {
|
.scroller {
|
||||||
margin-bottom: 1rem;
|
height: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ onBeforeRouteLeave(() => {
|
|||||||
.scroller {
|
.scroller {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding-bottom: 4rem;
|
padding-bottom: $content-padding-bottom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user