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

59 lines
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="collapsed">
<span v-if="q">Searching for <span class="font-thin">{{ q }}</span></span>
<span v-else>Search</span>
</ScreenHeader>
</template>
<div v-if="q" class="space-y-8">
2024-04-23 21:01:27 +00:00
<SongResultsBlock :query="q" :searching="searching" :songs="excerpt.songs" data-testid="song-excerpts" />
2024-04-04 22:20:42 +00:00
<ArtistResultsBlock :artists="excerpt.artists" :searching="searching" data-testid="artist-excerpts" />
<AlbumResultsBlock :albums="excerpt.albums" :searching="searching" data-testid="album-excerpts" />
2022-04-15 14:24:30 +00:00
</div>
2024-04-04 22:20:42 +00:00
<ScreenEmptyState v-else>
<template #icon>
<Icon :icon="faSearch" />
</template>
Find songs, artists, and albums,
<span class="secondary d-block">all in one place.</span>
</ScreenEmptyState>
</ScreenBase>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-07-15 07:23:55 +00:00
import { faSearch } from '@fortawesome/free-solid-svg-icons'
import { intersectionBy } from 'lodash'
import { ref, toRef } from 'vue'
2022-11-18 18:44:20 +00:00
import { eventBus } from '@/utils'
2022-04-15 14:24:30 +00:00
import { searchStore } from '@/stores'
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
2024-04-04 22:20:42 +00:00
import ScreenBase from '@/components/screens/ScreenBase.vue'
import SongResultsBlock from '@/components/screens/search/SongExcerptResultsBlock.vue'
import ArtistResultsBlock from '@/components/screens/search/ArtistExcerptResultsBlock.vue'
import AlbumResultsBlock from '@/components/screens/search/AlbumExcerptResultsBlock.vue'
const excerpt = toRef(searchStore.state, 'excerpt')
2022-04-15 17:00:08 +00:00
const q = ref('')
const searching = ref(false)
2022-04-15 14:24:30 +00:00
const doSearch = async () => {
searching.value = true
await searchStore.excerptSearch(q.value)
searching.value = false
}
eventBus.on('SEARCH_KEYWORDS_CHANGED', async _q => {
q.value = _q
await doSearch()
}).on('SONGS_DELETED', async songs => {
if (intersectionBy(songs, excerpt.value.songs, 'id').length !== 0) {
await doSearch()
}
2022-04-15 14:24:30 +00:00
})
</script>