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