2021-10-13 03:07:42 +02:00
|
|
|
<template>
|
2022-08-20 21:32:38 +02:00
|
|
|
<div v-if="currentLibrary" class="relative h-8 max-w-52 md:min-w-32" v-click-outside="clickOutsideObj">
|
2023-06-02 00:09:04 +02:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
:disabled="disabled"
|
|
|
|
class="w-10 sm:w-full relative h-full border border-white border-opacity-10 hover:border-opacity-20 rounded shadow-sm px-2 text-left text-sm cursor-pointer bg-black bg-opacity-20 text-gray-400 hover:text-gray-200"
|
2024-12-11 00:19:47 +01:00
|
|
|
aria-haspopup="menu"
|
2023-06-02 00:09:04 +02:00
|
|
|
:aria-expanded="showMenu"
|
|
|
|
:aria-label="$strings.ButtonLibrary + ': ' + currentLibrary.name"
|
|
|
|
@click.stop.prevent="clickShowMenu"
|
|
|
|
>
|
2022-07-27 01:54:32 +02:00
|
|
|
<div class="flex items-center justify-center sm:justify-start">
|
2022-10-18 19:09:36 +02:00
|
|
|
<ui-library-icon :icon="currentLibraryIcon" class="sm:mr-1.5" />
|
2022-07-27 01:54:32 +02:00
|
|
|
<span class="hidden sm:block truncate">{{ currentLibrary.name }}</span>
|
|
|
|
</div>
|
2021-10-13 03:07:42 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<transition name="menu">
|
2024-12-11 00:19:47 +01:00
|
|
|
<ul v-show="showMenu" class="absolute z-10 -mt-px w-full min-w-48 bg-primary border border-black-200 shadow-lg rounded-b-md py-1 overflow-auto focus:outline-none sm:text-sm librariesDropdownMenu" tabindex="-1" role="menu">
|
2021-10-23 03:08:02 +02:00
|
|
|
<template v-for="library in librariesFiltered">
|
2024-12-11 00:19:47 +01:00
|
|
|
<li :key="library.id" class="text-gray-400 hover:text-white relative py-2 cursor-pointer hover:bg-black-400" role="menuitem" tabindex="0" @keydown.enter="selectLibrary(library)" @click="selectLibrary(library)">
|
2022-07-27 01:54:32 +02:00
|
|
|
<div class="flex items-center px-2">
|
2022-10-18 19:09:36 +02:00
|
|
|
<ui-library-icon :icon="library.icon" class="mr-1.5" />
|
2021-10-13 03:07:42 +02:00
|
|
|
<span class="font-normal block truncate font-sans text-sm">{{ library.name }}</span>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2021-11-10 03:30:44 +01:00
|
|
|
clickOutsideObj: {
|
|
|
|
handler: this.clickedOutside,
|
|
|
|
events: ['mousedown'],
|
|
|
|
isActive: true
|
|
|
|
},
|
2021-10-13 03:07:42 +02:00
|
|
|
showMenu: false,
|
|
|
|
disabled: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
|
|
|
},
|
|
|
|
currentLibrary() {
|
|
|
|
return this.libraries.find((lib) => lib.id === this.currentLibraryId)
|
|
|
|
},
|
|
|
|
currentLibraryIcon() {
|
|
|
|
return this.currentLibrary ? this.currentLibrary.icon || 'database' : 'database'
|
|
|
|
},
|
|
|
|
libraries() {
|
|
|
|
return this.$store.getters['libraries/getSortedLibraries']()
|
|
|
|
},
|
2021-10-23 03:08:02 +02:00
|
|
|
canUserAccessAllLibraries() {
|
|
|
|
return this.$store.getters['user/getUserCanAccessAllLibraries']
|
|
|
|
},
|
|
|
|
userLibrariesAccessible() {
|
|
|
|
return this.$store.getters['user/getLibrariesAccessible']
|
|
|
|
},
|
|
|
|
librariesFiltered() {
|
|
|
|
if (this.canUserAccessAllLibraries) return this.libraries
|
|
|
|
return this.libraries.filter((lib) => {
|
|
|
|
return this.userLibrariesAccessible.includes(lib.id)
|
|
|
|
})
|
2021-10-13 03:07:42 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickShowMenu() {
|
|
|
|
if (this.disabled) return
|
|
|
|
this.showMenu = !this.showMenu
|
|
|
|
},
|
2021-11-10 03:30:44 +01:00
|
|
|
clickedOutside() {
|
2021-10-13 03:07:42 +02:00
|
|
|
this.showMenu = false
|
|
|
|
},
|
|
|
|
selectLibrary(library) {
|
|
|
|
this.updateLibrary(library)
|
|
|
|
this.showMenu = false
|
|
|
|
},
|
|
|
|
async updateLibrary(library) {
|
2021-12-01 03:02:40 +01:00
|
|
|
var currLibraryId = this.currentLibraryId
|
2024-05-02 00:23:49 +02:00
|
|
|
if (currLibraryId === library.id) {
|
|
|
|
return
|
|
|
|
}
|
2021-12-01 03:02:40 +01:00
|
|
|
|
2021-10-13 03:07:42 +02:00
|
|
|
this.disabled = true
|
|
|
|
await this.$store.dispatch('libraries/fetch', library.id)
|
2021-12-01 03:02:40 +01:00
|
|
|
|
2021-12-02 02:07:03 +01:00
|
|
|
if (this.$route.name.startsWith('config')) {
|
|
|
|
// No need to refresh
|
2024-05-02 00:23:49 +02:00
|
|
|
} else if (this.$route.name === 'library-library-series-id' && library.mediaType === 'book') {
|
|
|
|
// For series item page redirect to root series page
|
|
|
|
this.$router.push(`/library/${library.id}/bookshelf/series`)
|
2024-07-21 17:52:23 +02:00
|
|
|
} else if (this.$route.name === 'library-library-search') {
|
|
|
|
this.$router.push(this.$route.fullPath.replace(currLibraryId, library.id))
|
|
|
|
} else if (this.$route.name.startsWith('library')) {
|
|
|
|
this.$router.push(this.$route.path.replace(currLibraryId, library.id))
|
2021-12-01 03:02:40 +01:00
|
|
|
} else {
|
|
|
|
this.$router.push(`/library/${library.id}`)
|
|
|
|
}
|
|
|
|
|
2021-10-13 03:07:42 +02:00
|
|
|
this.disabled = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
2023-06-02 00:09:04 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.librariesDropdownMenu {
|
|
|
|
max-height: calc(100vh - 75px);
|
|
|
|
}
|
2024-05-02 00:23:49 +02:00
|
|
|
</style>
|