2021-08-21 23:23:35 +02:00
|
|
|
<template>
|
2021-10-09 18:09:06 +02:00
|
|
|
<div class="w-80 ml-6 relative">
|
2021-09-24 23:14:33 +02:00
|
|
|
<form @submit.prevent="submitSearch">
|
|
|
|
<ui-text-input ref="input" v-model="search" placeholder="Search.." @input="inputUpdate" @focus="focussed" @blur="blurred" class="w-full h-8 text-sm" />
|
|
|
|
</form>
|
2021-08-21 23:23:35 +02:00
|
|
|
<div class="absolute top-0 right-0 bottom-0 h-full flex items-center px-2 text-gray-400 cursor-pointer" @click="clickClear">
|
|
|
|
<span v-if="!search" class="material-icons" style="font-size: 1.2rem">search</span>
|
|
|
|
<span v-else class="material-icons" style="font-size: 1.2rem">close</span>
|
|
|
|
</div>
|
2021-10-09 18:09:06 +02:00
|
|
|
<div v-show="showMenu && (lastSearch || isTyping)" class="absolute z-40 -mt-px w-full bg-bg border border-black-200 shadow-lg rounded-md py-1 px-2 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm globalSearchMenu">
|
2021-08-21 23:23:35 +02:00
|
|
|
<ul class="h-full w-full" role="listbox" aria-labelledby="listbox-label">
|
|
|
|
<li v-if="isTyping" class="py-2 px-2">
|
2021-10-09 18:09:06 +02:00
|
|
|
<p>Thinking...</p>
|
2021-08-21 23:23:35 +02:00
|
|
|
</li>
|
|
|
|
<li v-else-if="isFetching" class="py-2 px-2">
|
|
|
|
<p>Fetching...</p>
|
|
|
|
</li>
|
2021-10-09 18:09:06 +02:00
|
|
|
<li v-else-if="!totalResults" class="py-2 px-2">
|
2021-08-21 23:23:35 +02:00
|
|
|
<p>No Results</p>
|
|
|
|
</li>
|
|
|
|
<template v-else>
|
2021-10-09 18:09:06 +02:00
|
|
|
<p class="uppercase text-xs text-gray-400 my-1 px-1 font-semibold">Books</p>
|
|
|
|
<template v-for="item in audiobookResults">
|
|
|
|
<li :key="item.audiobook.id" class="text-gray-50 select-none relative cursor-pointer hover:bg-black-400 py-1" role="option">
|
|
|
|
<nuxt-link :to="`/audiobook/${item.audiobook.id}`">
|
|
|
|
<cards-audiobook-search-card :audiobook="item.audiobook" />
|
|
|
|
</nuxt-link>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<p v-if="authorResults.length" class="uppercase text-xs text-gray-400 mb-1 mt-3 px-1 font-semibold">Authors</p>
|
|
|
|
<template v-for="item in authorResults">
|
|
|
|
<li :key="item.author" class="text-gray-50 select-none relative cursor-pointer hover:bg-black-400 py-1" role="option">
|
|
|
|
<nuxt-link :to="`/library/${currentLibraryId}/bookshelf?filter=authors.${$encode(item.author)}`">
|
|
|
|
<cards-author-search-card :author="item.author" />
|
|
|
|
</nuxt-link>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<p v-if="seriesResults.length" class="uppercase text-xs text-gray-400 mb-1 mt-3 px-1 font-semibold">Series</p>
|
|
|
|
<template v-for="item in seriesResults">
|
|
|
|
<li :key="item.series" class="text-gray-50 select-none relative cursor-pointer hover:bg-black-400 py-1" role="option" @click="clickedOption(item.series)">
|
|
|
|
<nuxt-link :to="`/library/${currentLibraryId}/bookshelf/series?series=${$encode(item.series)}`">
|
|
|
|
<cards-series-search-card :series="item.series" :book-items="item.audiobooks" />
|
|
|
|
</nuxt-link>
|
2021-08-21 23:23:35 +02:00
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showMenu: false,
|
|
|
|
isFocused: false,
|
|
|
|
focusTimeout: null,
|
|
|
|
isTyping: false,
|
|
|
|
isFetching: false,
|
|
|
|
search: null,
|
2021-10-09 18:09:06 +02:00
|
|
|
audiobookResults: [],
|
|
|
|
authorResults: [],
|
|
|
|
seriesResults: [],
|
2021-08-21 23:23:35 +02:00
|
|
|
searchTimeout: null,
|
|
|
|
lastSearch: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
audiobooks() {
|
|
|
|
return this.$store.state.audiobooks.audiobooks
|
2021-10-06 04:10:49 +02:00
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
2021-10-09 18:09:06 +02:00
|
|
|
},
|
|
|
|
totalResults() {
|
|
|
|
return this.audiobookResults.length + this.seriesResults.length + this.authorResults.length
|
2021-08-21 23:23:35 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-09-24 23:14:33 +02:00
|
|
|
submitSearch() {
|
|
|
|
if (!this.search) return
|
2021-10-06 04:10:49 +02:00
|
|
|
this.$router.push(`/library/${this.currentLibraryId}/bookshelf/search?query=${this.search}`)
|
2021-09-24 23:14:33 +02:00
|
|
|
|
|
|
|
this.search = null
|
2021-10-09 18:09:06 +02:00
|
|
|
this.audiobookResults = []
|
|
|
|
this.authorResults = []
|
|
|
|
this.seriesResults = []
|
2021-09-24 23:14:33 +02:00
|
|
|
this.showMenu = false
|
|
|
|
this.$nextTick(() => {
|
|
|
|
if (this.$refs.input) {
|
|
|
|
this.$refs.input.blur()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2021-08-21 23:23:35 +02:00
|
|
|
focussed() {
|
|
|
|
this.isFocused = true
|
|
|
|
this.showMenu = true
|
|
|
|
},
|
|
|
|
blurred() {
|
|
|
|
this.isFocused = false
|
|
|
|
clearTimeout(this.focusTimeout)
|
|
|
|
this.focusTimeout = setTimeout(() => {
|
|
|
|
this.showMenu = false
|
|
|
|
}, 200)
|
|
|
|
},
|
|
|
|
async runSearch(value) {
|
|
|
|
this.lastSearch = value
|
|
|
|
if (!this.lastSearch) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.isFetching = true
|
2021-10-09 18:09:06 +02:00
|
|
|
|
|
|
|
var searchResults = await this.$axios.$get(`/api/library/${this.currentLibraryId}/search?q=${value}`).catch((error) => {
|
2021-08-21 23:23:35 +02:00
|
|
|
console.error('Search error', error)
|
|
|
|
return []
|
|
|
|
})
|
2021-10-09 18:09:06 +02:00
|
|
|
this.audiobookResults = searchResults.audiobooks || []
|
|
|
|
this.authorResults = searchResults.authors || []
|
|
|
|
this.seriesResults = searchResults.series || []
|
|
|
|
|
2021-08-21 23:23:35 +02:00
|
|
|
this.isFetching = false
|
2021-09-24 23:14:33 +02:00
|
|
|
if (!this.showMenu) {
|
|
|
|
return
|
|
|
|
}
|
2021-08-21 23:23:35 +02:00
|
|
|
},
|
|
|
|
inputUpdate(val) {
|
|
|
|
clearTimeout(this.searchTimeout)
|
|
|
|
if (!val) {
|
|
|
|
this.lastSearch = ''
|
|
|
|
this.isTyping = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.isTyping = true
|
|
|
|
this.searchTimeout = setTimeout(() => {
|
|
|
|
this.isTyping = false
|
|
|
|
this.runSearch(val)
|
2021-10-09 18:09:06 +02:00
|
|
|
}, 750)
|
2021-08-21 23:23:35 +02:00
|
|
|
},
|
|
|
|
clickClear() {
|
|
|
|
if (this.search) {
|
|
|
|
this.search = null
|
2021-10-09 18:09:06 +02:00
|
|
|
this.lastSearch = null
|
|
|
|
this.audiobookResults = []
|
|
|
|
this.authorResults = []
|
|
|
|
this.seriesResults = []
|
2021-08-21 23:23:35 +02:00
|
|
|
this.showMenu = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
2021-10-09 18:09:06 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.globalSearchMenu {
|
|
|
|
max-height: 80vh;
|
|
|
|
}
|
|
|
|
</style>
|