2021-12-01 03:02:40 +01:00
|
|
|
<template>
|
2022-03-14 01:34:31 +01:00
|
|
|
<div class="page" :class="streamLibraryItem ? 'streaming' : ''">
|
2021-12-01 03:02:40 +01:00
|
|
|
<div class="flex h-full">
|
|
|
|
<app-side-rail class="hidden md:block" />
|
|
|
|
<div class="flex-grow">
|
2021-12-02 02:07:03 +01:00
|
|
|
<app-book-shelf-toolbar is-home page="search" :search-query="query" />
|
|
|
|
<app-book-shelf-categorized v-if="hasResults" ref="bookshelf" search :results="results" />
|
2021-12-01 03:02:40 +01:00
|
|
|
<div v-else class="w-full py-16">
|
|
|
|
<p class="text-xl text-center">No Search results for "{{ query }}"</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
async asyncData({ store, params, redirect, query, app }) {
|
|
|
|
var libraryId = params.library
|
2021-12-02 02:07:03 +01:00
|
|
|
var library = await store.dispatch('libraries/fetch', libraryId)
|
|
|
|
if (!library) {
|
|
|
|
return redirect('/oops?message=Library not found')
|
|
|
|
}
|
2021-12-01 03:02:40 +01:00
|
|
|
var query = query.q
|
|
|
|
var results = await app.$axios.$get(`/api/libraries/${libraryId}/search?q=${query}`).catch((error) => {
|
|
|
|
console.error('Failed to search library', error)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
results = {
|
2022-04-12 23:54:52 +02:00
|
|
|
podcasts: results && results.podcast ? results.podcast : null,
|
|
|
|
books: results && results.book ? results.book : null,
|
2021-12-01 03:02:40 +01:00
|
|
|
authors: results && results.authors.length ? results.authors : null,
|
|
|
|
series: results && results.series.length ? results.series : null,
|
|
|
|
tags: results && results.tags.length ? results.tags : null
|
|
|
|
}
|
|
|
|
return {
|
2021-12-02 02:07:03 +01:00
|
|
|
libraryId,
|
2021-12-01 03:02:40 +01:00
|
|
|
results,
|
|
|
|
query
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {}
|
|
|
|
},
|
2021-12-02 02:07:03 +01:00
|
|
|
watch: {
|
|
|
|
'$route.query'(newVal, oldVal) {
|
|
|
|
if (newVal && newVal.q && newVal.q !== this.query) {
|
|
|
|
this.query = newVal.q
|
|
|
|
this.search()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-12-01 03:02:40 +01:00
|
|
|
computed: {
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2021-12-01 03:02:40 +01:00
|
|
|
},
|
|
|
|
hasResults() {
|
2022-04-12 23:54:52 +02:00
|
|
|
return Object.values(this.results).find((r) => !!r && r.length)
|
2021-12-01 03:02:40 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-12-02 02:07:03 +01:00
|
|
|
async search() {
|
|
|
|
var results = await this.$axios.$get(`/api/libraries/${this.libraryId}/search?q=${this.query}`).catch((error) => {
|
|
|
|
console.error('Failed to search library', error)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
this.results = {
|
2022-04-12 23:54:52 +02:00
|
|
|
podcasts: results && results.podcast ? results.podcast : null,
|
|
|
|
books: results && results.book ? results.book : null,
|
2021-12-02 02:07:03 +01:00
|
|
|
authors: results && results.authors.length ? results.authors : null,
|
|
|
|
series: results && results.series.length ? results.series : null,
|
|
|
|
tags: results && results.tags.length ? results.tags : null
|
|
|
|
}
|
|
|
|
this.$nextTick(() => {
|
|
|
|
if (this.$refs.bookshelf) {
|
|
|
|
this.$refs.bookshelf.setShelvesFromSearch()
|
|
|
|
}
|
|
|
|
})
|
2021-12-01 03:02:40 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {},
|
|
|
|
beforeDestroy() {}
|
|
|
|
}
|
|
|
|
</script>
|