feat: auto load more search track results

This commit is contained in:
geoffrey45 2023-01-02 20:55:15 +03:00 committed by Mungai Njoroge
parent 1d03b21caf
commit 3d37cd59b3
4 changed files with 63 additions and 14 deletions

View File

@ -0,0 +1,12 @@
<template></template>
<script setup lang="ts">
import { onMounted } from "vue";
const props = defineProps<{
action: () => void;
}>();
onMounted(() => {
props.action();
});
</script>

View File

@ -13,4 +13,12 @@ import AlbumCard from "@/components/shared/AlbumCard.vue";
import useSearchStore from "@/stores/search"; import useSearchStore from "@/stores/search";
const search = useSearchStore(); const search = useSearchStore();
</script> </script>
<style lang="scss">
.search-albums-view.grid-page {
padding-right: $small;
overflow: auto;
}
</style>

View File

@ -15,10 +15,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { Routes } from "@/router/routes"; import { Routes } from "@/router/routes";
import useSearchStore from "@/stores/search";
import { focusElemByClass } from "@/utils";
import { computed, onMounted, ref } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { computed, onMounted, ref } from "vue";
import { focusElemByClass } from "@/utils";
import useSearchStore from "@/stores/search";
import AlbumPage from "./albums.vue"; import AlbumPage from "./albums.vue";
import ArtistPage from "./artists.vue"; import ArtistPage from "./artists.vue";
import TracksPage from "./tracks.vue"; import TracksPage from "./tracks.vue";
@ -55,7 +57,7 @@ const component = computed(() => {
function loadTracks() { function loadTracks() {
search.loadTracks(); search.loadTracks();
focusElemByClass("page-bottom-padding", 100); focusElemByClass("track-11", 100);
} }
function getGridRowItemCount() { function getGridRowItemCount() {

View File

@ -1,20 +1,17 @@
<template> <template>
<div class="search-tracks-view"> <div class="search-tracks-view">
<div <div :class="{ isSmall, isMedium }" style="height: 100%">
:class="{ isSmall, isMedium }"
style="height: 100%"
>
<RecycleScroller <RecycleScroller
id="songlist-scroller" id="songlist-scroller"
style="height: 100%" style="height: 100%"
:items="search.tracks.value.map((track) => ({ track, id: Math.random() }))" :items="scrollerItems"
:item-size="64" :item-size="64"
key-field="id" key-field="id"
v-slot="{ item, index }" v-slot="{ item, index }"
> >
<SongItem <component
:track="item.track" :is="item.component"
:index="index + 1" v-bind="item.props"
@playThis="playFromSearch(index)" @playThis="playFromSearch(index)"
/> />
</RecycleScroller> </RecycleScroller>
@ -23,14 +20,44 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed } from "vue";
import useQueueStore from "@/stores/queue"; import useQueueStore from "@/stores/queue";
import useSearchStore from "@/stores/search"; import useSearchStore from "@/stores/search";
import { isMedium, isSmall } from "@/stores/content-width"; import { isMedium, isSmall } from "@/stores/content-width";
import SongItem from "@/components/shared/SongItem.vue"; import SongItem from "@/components/shared/SongItem.vue";
import FetchMore from "@/components/SearchPage/FetchMore.vue";
const search = useSearchStore(); const search = useSearchStore();
const queue = useQueueStore(); const queue = useQueueStore();
interface scrollerItem {
id: number;
component: typeof SongItem | typeof FetchMore;
props: Record<string, any>;
}
const scrollerItems = computed(() => {
const items: scrollerItem[] = search.tracks.value.map((track, index) => ({
id: Math.random(),
component: SongItem,
props: {
track,
index: index + 1,
},
}));
items.push({
id: Math.random(),
component: FetchMore,
props: {
action: search.loadTracks,
},
});
return items;
});
function playFromSearch(index: number) { function playFromSearch(index: number) {
queue.playFromSearch(search.query, search.tracks.value); queue.playFromSearch(search.query, search.tracks.value);
queue.play(index); queue.play(index);
@ -45,7 +72,7 @@ function playFromSearch(index: number) {
height: 100%; height: 100%;
} }
#songlist-scroller{ #songlist-scroller {
padding-right: 1rem; padding-right: 1rem;
padding-left: 0; padding-left: 0;
} }