2021-09-23 03:40:35 +02:00
|
|
|
<template>
|
|
|
|
<div class="page" :class="streamAudiobook ? 'streaming' : ''">
|
|
|
|
<div class="flex h-full">
|
2021-11-04 23:35:59 +01:00
|
|
|
<app-side-rail class="hidden md:block" />
|
2021-09-23 03:40:35 +02:00
|
|
|
<div class="flex-grow">
|
2021-10-30 03:42:28 +02:00
|
|
|
<app-book-shelf-toolbar :page="id || ''" :search-results="searchResults" :search-query="searchQuery" :selected-series.sync="selectedSeries" :view-mode.sync="viewMode" />
|
|
|
|
<app-book-shelf :page="id || ''" :search-results="searchResults" :search-query="searchQuery" :selected-series.sync="selectedSeries" :view-mode="viewMode" />
|
2021-09-23 03:40:35 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2021-10-05 05:11:42 +02:00
|
|
|
async asyncData({ params, query, store, app, redirect }) {
|
|
|
|
var libraryId = params.library
|
|
|
|
var library = await store.dispatch('libraries/fetch', libraryId)
|
|
|
|
if (!library) {
|
|
|
|
return redirect('/oops?message=Library not found')
|
|
|
|
}
|
|
|
|
|
2021-10-17 18:29:52 +02:00
|
|
|
// Set filter by
|
2021-09-24 14:32:38 +02:00
|
|
|
if (query.filter) {
|
|
|
|
store.dispatch('user/updateUserSettings', { filterBy: query.filter })
|
|
|
|
}
|
2021-10-17 18:29:52 +02:00
|
|
|
|
|
|
|
// Search page
|
|
|
|
var searchResults = {}
|
|
|
|
var audiobookSearchResults = []
|
2021-09-24 23:14:33 +02:00
|
|
|
var searchQuery = null
|
|
|
|
if (params.id === 'search' && query.query) {
|
|
|
|
searchQuery = query.query
|
2021-10-17 18:29:52 +02:00
|
|
|
|
|
|
|
searchResults = await app.$axios.$get(`/api/library/${libraryId}/search?q=${searchQuery}`).catch((error) => {
|
2021-09-24 23:14:33 +02:00
|
|
|
console.error('Search error', error)
|
2021-10-17 18:29:52 +02:00
|
|
|
return {}
|
2021-09-24 23:14:33 +02:00
|
|
|
})
|
2021-10-17 18:29:52 +02:00
|
|
|
audiobookSearchResults = searchResults.audiobooks || []
|
2021-09-27 13:52:21 +02:00
|
|
|
store.commit('audiobooks/setSearchResults', searchResults)
|
2021-10-17 18:29:52 +02:00
|
|
|
if (audiobookSearchResults.length) audiobookSearchResults.forEach((ab) => store.commit('audiobooks/addUpdate', ab.audiobook))
|
2021-09-24 23:14:33 +02:00
|
|
|
}
|
2021-10-17 18:29:52 +02:00
|
|
|
|
|
|
|
// Series page
|
2021-09-27 13:52:21 +02:00
|
|
|
var selectedSeries = query.series ? app.$decode(query.series) : null
|
|
|
|
store.commit('audiobooks/setSelectedSeries', selectedSeries)
|
2021-10-17 18:29:52 +02:00
|
|
|
|
2021-09-27 13:52:21 +02:00
|
|
|
var libraryPage = params.id || ''
|
|
|
|
store.commit('audiobooks/setLibraryPage', libraryPage)
|
|
|
|
|
2021-11-06 02:24:02 +01:00
|
|
|
if (libraryPage === 'collections') {
|
|
|
|
store.dispatch('user/loadUserCollections')
|
|
|
|
}
|
|
|
|
|
2021-09-23 03:40:35 +02:00
|
|
|
return {
|
2021-09-27 13:52:21 +02:00
|
|
|
id: libraryPage,
|
2021-10-17 18:29:52 +02:00
|
|
|
libraryId,
|
2021-09-24 23:14:33 +02:00
|
|
|
searchQuery,
|
|
|
|
searchResults,
|
2021-09-27 13:52:21 +02:00
|
|
|
selectedSeries
|
2021-09-23 03:40:35 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2021-10-30 03:42:28 +02:00
|
|
|
return {
|
|
|
|
viewMode: 'grid'
|
|
|
|
}
|
2021-09-23 03:40:35 +02:00
|
|
|
},
|
2021-09-24 23:14:33 +02:00
|
|
|
watch: {
|
|
|
|
'$route.query'(newVal) {
|
|
|
|
if (this.id === 'search' && this.$route.query.query) {
|
|
|
|
if (this.$route.query.query !== this.searchQuery) {
|
|
|
|
this.newQuery()
|
|
|
|
}
|
2021-10-27 01:24:42 +02:00
|
|
|
} else if (this.id === 'series') {
|
|
|
|
if (this.selectedSeries && this.$route.query.series && this.$route.query.series !== this.$encode(this.selectedSeries)) {
|
|
|
|
// Series changed
|
|
|
|
this.selectedSeries = this.$decode(this.$route.query.series)
|
|
|
|
} else if (!this.selectedSeries && this.$route.query.series) {
|
|
|
|
// Series selected
|
|
|
|
this.selectedSeries = this.$decode(this.$route.query.series)
|
|
|
|
} else if (this.selectedSeries && !this.$route.query.series) {
|
|
|
|
// Series unselected
|
|
|
|
this.selectedSeries = null
|
|
|
|
}
|
2021-09-24 23:14:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-09-23 03:40:35 +02:00
|
|
|
computed: {
|
|
|
|
streamAudiobook() {
|
|
|
|
return this.$store.state.streamAudiobook
|
|
|
|
}
|
|
|
|
},
|
2021-09-24 23:14:33 +02:00
|
|
|
methods: {
|
|
|
|
async newQuery() {
|
|
|
|
var query = this.$route.query.query
|
2021-10-17 18:29:52 +02:00
|
|
|
this.searchResults = await this.$axios.$get(`/api/library/${this.libraryId}/search?q=${query}`).catch((error) => {
|
2021-09-24 23:14:33 +02:00
|
|
|
console.error('Search error', error)
|
2021-10-17 18:29:52 +02:00
|
|
|
return {}
|
2021-09-24 23:14:33 +02:00
|
|
|
})
|
|
|
|
this.searchQuery = query
|
|
|
|
}
|
2021-11-08 01:11:29 +01:00
|
|
|
}
|
2021-09-23 03:40:35 +02:00
|
|
|
}
|
|
|
|
</script>
|