koel/resources/assets/js/components/screens/search/SearchSongResultsScreen.vue

88 lines
2.2 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<ScreenBase>
<template #header>
<ScreenHeader :layout="songs.length === 0 ? 'collapsed' : headerLayout">
2024-05-19 05:49:42 +00:00
Results for <span class="font-thin">{{ decodedQ }}</span>
2024-04-04 22:20:42 +00:00
<ControlsToggle v-model="showingControls" />
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<template #thumbnail>
<ThumbnailStack :thumbnails="thumbnails" />
</template>
2022-07-16 09:52:39 +00:00
2024-04-04 22:20:42 +00:00
<template v-if="songs.length" #meta>
2024-05-19 05:49:42 +00:00
<span>{{ pluralize(songs, 'item') }}</span>
2024-04-04 22:20:42 +00:00
<span>{{ duration }}</span>
</template>
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<template #controls>
<SongListControls
v-if="songs.length && (!isPhone || showingControls)"
:config="config"
@filter="applyFilter"
@play-all="playAll"
@play-selected="playSelected"
/>
</template>
</ScreenHeader>
</template>
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<SongListSkeleton v-if="loading" class="-m-6" />
<SongList
v-else
ref="songList"
class="-m-6"
@sort="sort"
@press:enter="onPressEnter"
@scroll-breakpoint="onScrollBreakpoint"
/>
</ScreenBase>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, onMounted, ref, toRef } from 'vue'
2022-04-15 14:24:30 +00:00
import { searchStore } from '@/stores'
2024-01-18 11:13:05 +00:00
import { useRouter, useSongList, useSongListControls } from '@/composables'
2022-11-18 18:44:20 +00:00
import { pluralize } from '@/utils'
2022-04-15 14:24:30 +00:00
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import SongListSkeleton from '@/components/ui/skeletons/SongListSkeleton.vue'
2024-04-04 22:20:42 +00:00
import ScreenBase from '@/components/screens/ScreenBase.vue'
2022-04-21 16:06:45 +00:00
2022-11-18 18:44:20 +00:00
const { getRouteParam } = useRouter()
const q = ref('')
2022-04-15 17:00:08 +00:00
const {
SongList,
2022-06-10 10:47:46 +00:00
ControlsToggle,
2022-07-16 09:52:39 +00:00
ThumbnailStack,
headerLayout,
2022-04-21 16:06:45 +00:00
songs,
2022-04-15 17:00:08 +00:00
songList,
2022-07-16 09:52:39 +00:00
thumbnails,
2022-04-23 21:24:02 +00:00
duration,
2022-04-15 17:00:08 +00:00
showingControls,
isPhone,
onPressEnter,
2022-04-15 17:00:08 +00:00
playAll,
playSelected,
applyFilter,
2022-07-16 09:52:39 +00:00
sort,
onScrollBreakpoint
2024-03-25 22:59:38 +00:00
} = useSongList(toRef(searchStore.state, 'songs'), { type: 'Search.Songs' })
2022-04-15 17:00:08 +00:00
2024-01-18 11:13:05 +00:00
const { SongListControls, config } = useSongListControls('Search.Songs')
2022-04-15 17:00:08 +00:00
const decodedQ = computed(() => decodeURIComponent(q.value))
const loading = ref(false)
2022-04-15 17:00:08 +00:00
searchStore.resetSongResultState()
onMounted(async () => {
2022-11-18 18:44:20 +00:00
q.value = getRouteParam('q') || ''
if (!q.value) return
loading.value = true
await searchStore.songSearch(q.value)
loading.value = false
})
2022-04-15 14:24:30 +00:00
</script>