audiobookshelf/client/components/app/BookShelfToolbar.vue

72 lines
1.8 KiB
Vue
Raw Normal View History

<template>
<div class="w-full h-10 relative">
<div id="toolbar" class="absolute top-0 left-0 w-full h-full z-20 flex items-center px-8">
2021-08-19 03:18:44 +02:00
<p class="font-book">{{ numShowing }} Audiobooks</p>
<div class="flex-grow" />
<ui-text-input v-model="_keywordFilter" placeholder="Keyword Filter" :padding-y="1.5" class="text-xs w-40" />
<controls-filter-select v-model="settings.filterBy" class="w-48 h-7.5 ml-4" @change="updateFilter" />
<controls-order-select v-model="settings.orderBy" :descending.sync="settings.orderDesc" class="w-48 h-7.5 ml-4" @change="updateOrder" />
</div>
</div>
</template>
<script>
export default {
data() {
2021-08-19 03:18:44 +02:00
return {
settings: {},
hasInit: false
2021-08-19 03:18:44 +02:00
}
},
computed: {
2021-08-19 03:18:44 +02:00
numShowing() {
return this.$store.getters['audiobooks/getFiltered']().length
},
_keywordFilter: {
get() {
return this.$store.state.audiobooks.keywordFilter
},
set(val) {
this.$store.commit('audiobooks/setKeywordFilter', val)
}
2021-08-19 03:18:44 +02:00
}
},
methods: {
updateOrder() {
this.saveSettings()
},
updateFilter() {
this.saveSettings()
},
saveSettings() {
this.$store.commit('user/setSettings', this.settings) // Immediate update
this.$store.dispatch('user/updateUserSettings', this.settings)
},
2021-08-19 03:18:44 +02:00
init() {
this.settings = { ...this.$store.state.user.settings }
},
settingsUpdated(settings) {
for (const key in settings) {
this.settings[key] = settings[key]
}
}
},
2021-08-19 03:18:44 +02:00
mounted() {
this.init()
this.$store.commit('user/addSettingsListener', { id: 'bookshelftoolbar', meth: this.settingsUpdated })
},
beforeDestroy() {
this.$store.commit('user/removeSettingsListener', 'bookshelftoolbar')
2021-08-19 03:18:44 +02:00
}
}
</script>
<style>
#toolbar {
box-shadow: 0px 8px 8px #111111aa;
}
</style>