mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
rewrite album view using @Akryum/vue-virtual-scroller
This commit is contained in:
committed by
Mungai Njoroge
parent
b3b7da701b
commit
9cde9d0aa4
+9
-7
@@ -2,30 +2,32 @@ import { createApp } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
|
||||
import {
|
||||
RecycleScroller,
|
||||
DynamicScroller,
|
||||
DynamicScrollerItem,
|
||||
// @ts-ignore
|
||||
RecycleScroller,
|
||||
DynamicScroller,
|
||||
DynamicScrollerItem,
|
||||
// @ts-ignore
|
||||
} from "vue-virtual-scroller";
|
||||
|
||||
import { autoAnimatePlugin } from "@formkit/auto-animate/vue";
|
||||
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
|
||||
|
||||
import "./assets/scss/index.scss";
|
||||
import "vue-virtual-scroller/dist/vue-virtual-scroller.css";
|
||||
|
||||
import App from "./App.vue";
|
||||
import router from "./router";
|
||||
import vTooltip from "./directives/vTooltip";
|
||||
|
||||
import "./assets/scss/index.scss";
|
||||
import "vue-virtual-scroller/dist/vue-virtual-scroller.css";
|
||||
|
||||
const app = createApp(App);
|
||||
const pinia = createPinia();
|
||||
pinia.use(piniaPluginPersistedstate);
|
||||
|
||||
app.use(pinia);
|
||||
app.use(router);
|
||||
app.directive("tooltip", vTooltip);
|
||||
app.use(autoAnimatePlugin);
|
||||
|
||||
app.directive("tooltip", vTooltip);
|
||||
app.component("RecycleScroller", RecycleScroller);
|
||||
app.component("DynamicScroller", DynamicScroller);
|
||||
app.component("DynamicScrollerItem", DynamicScrollerItem);
|
||||
|
||||
@@ -5,6 +5,7 @@ import useFuse from "./useFuse";
|
||||
import { readLocalStorage, writeLocalStorage } from "./useLocalStorage";
|
||||
import putCommas from "./usePutCommas";
|
||||
import useVisibility from "./useVisibility";
|
||||
import useCreateTrackProps from "./useCreateTrackProps";
|
||||
|
||||
export {
|
||||
readLocalStorage,
|
||||
@@ -13,6 +14,7 @@ export {
|
||||
focusElemByClass,
|
||||
useVisibility,
|
||||
formatSeconds,
|
||||
useCreateTrackProps as createTrackProps,
|
||||
putCommas,
|
||||
useFuse,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Track } from "@/interfaces";
|
||||
import queue from "@/stores/queue";
|
||||
|
||||
export default function createTrackProps(track: Track) {
|
||||
return {
|
||||
track,
|
||||
index: track.index + 1,
|
||||
isCurrent: queue().currenttrack?.hash === track.hash,
|
||||
isCurrentPlaying:
|
||||
queue().currenttrack?.hash === track.hash && queue().playing,
|
||||
};
|
||||
}
|
||||
@@ -1,43 +1,89 @@
|
||||
<template>
|
||||
<Layout
|
||||
:tracks="album.tracks"
|
||||
@playFromPage="playFromAlbum"
|
||||
:on_album_page="true"
|
||||
>
|
||||
<template #header>
|
||||
<Header :album="album.info" />
|
||||
</template>
|
||||
</Layout>
|
||||
<div class="album-virtual-scroller v-scroll-page">
|
||||
<RecycleScroller
|
||||
class="scroller"
|
||||
:items="scrollerItems"
|
||||
:item-size="null"
|
||||
key-field="id"
|
||||
v-slot="{ item }"
|
||||
>
|
||||
<component
|
||||
:is="item.component"
|
||||
v-bind="item.props"
|
||||
@playThis="playFromAlbum(item.props.index - item.props.track.disc - 1)"
|
||||
/>
|
||||
</RecycleScroller>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// @libs
|
||||
import {
|
||||
onBeforeRouteLeave,
|
||||
onBeforeRouteUpdate,
|
||||
RouteLocationNormalized,
|
||||
} from "vue-router";
|
||||
import { computed } from "@vue/reactivity";
|
||||
|
||||
import { Track } from "@/interfaces";
|
||||
import { createTrackProps } from "@/utils";
|
||||
|
||||
// @stores
|
||||
import useQueueStore from "@/stores/queue";
|
||||
import useAStore from "@/stores/pages/album";
|
||||
import useAlbumStore from "@/stores/pages/album";
|
||||
|
||||
// @components
|
||||
import Header from "@/components/AlbumView/Header.vue";
|
||||
import Layout from "@/layouts/HeaderAndVList.vue";
|
||||
import SongItem from "@/components/shared/SongItem.vue";
|
||||
import AlbumDiscBar from "@/components/AlbumView/AlbumDiscBar.vue";
|
||||
|
||||
// @vars
|
||||
const album = useAStore();
|
||||
const album = useAlbumStore();
|
||||
const queue = useQueueStore();
|
||||
|
||||
// @methods
|
||||
interface ScrollerItem {
|
||||
id: string;
|
||||
component: typeof Header | typeof SongItem;
|
||||
props: Record<string, unknown>;
|
||||
size: number;
|
||||
}
|
||||
|
||||
class songItem {
|
||||
id: number;
|
||||
props = {};
|
||||
size = 64;
|
||||
component: typeof SongItem | typeof AlbumDiscBar;
|
||||
|
||||
constructor(track: Track) {
|
||||
this.id = Math.random();
|
||||
this.props = track.is_album_disc_number
|
||||
? { album_disc: track }
|
||||
: createTrackProps(track);
|
||||
this.component = track.is_album_disc_number ? AlbumDiscBar : SongItem;
|
||||
}
|
||||
}
|
||||
|
||||
function getSongItems() {
|
||||
return album.tracks.map((track) => {
|
||||
return new songItem(track);
|
||||
});
|
||||
}
|
||||
|
||||
const scrollerItems = computed(() => {
|
||||
const header: ScrollerItem = {
|
||||
id: "album-header",
|
||||
component: Header,
|
||||
props: {
|
||||
album: album.info,
|
||||
},
|
||||
size: 18 * 16,
|
||||
};
|
||||
|
||||
return [header, ...getSongItems()];
|
||||
});
|
||||
|
||||
function playFromAlbum(index: number) {
|
||||
const { title, artist, hash } = album.info;
|
||||
queue.playFromAlbum(title, artist, hash, album.allTracks);
|
||||
queue.play(index);
|
||||
}
|
||||
|
||||
// @hooks
|
||||
onBeforeRouteUpdate(async (to: RouteLocationNormalized) => {
|
||||
await album
|
||||
.fetchTracksAndArtists(to.params.hash.toString())
|
||||
@@ -50,3 +96,12 @@ onBeforeRouteLeave(() => {
|
||||
}, 500);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.album-virtual-scroller {
|
||||
height: 100%;
|
||||
.scroller {
|
||||
padding-bottom: $content-padding-bottom;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -48,8 +48,8 @@ interface ScrollerItem {
|
||||
|
||||
class songItem {
|
||||
id: string;
|
||||
component = SongItem;
|
||||
props: any;
|
||||
component = SongItem;
|
||||
|
||||
constructor(track: Track) {
|
||||
this.id = track.trackid;
|
||||
|
||||
Reference in New Issue
Block a user