2022-05-09 01:21:46 +02:00
|
|
|
<template>
|
|
|
|
<div class="w-full">
|
2024-06-23 18:15:39 +02:00
|
|
|
<div class="flex items-center py-3e">
|
2022-05-09 01:21:46 +02:00
|
|
|
<slot />
|
|
|
|
<div class="flex-grow" />
|
2024-06-23 18:15:39 +02:00
|
|
|
<button cy-id="leftScrollButton" v-if="isScrollable" class="w-8e h-8e mx-1e flex items-center justify-center rounded-full" :class="canScrollLeft ? 'hover:bg-white hover:bg-opacity-5 text-gray-300 hover:text-white' : 'text-white text-opacity-40 cursor-text'" @click="scrollLeft">
|
|
|
|
<span class="material-icons" :style="{ fontSize: 1.5 + 'em' }">chevron_left</span>
|
2022-05-09 01:21:46 +02:00
|
|
|
</button>
|
2024-06-23 18:15:39 +02:00
|
|
|
<button cy-id="rightScrollButton" v-if="isScrollable" class="w-8e h-8e mx-1e flex items-center justify-center rounded-full" :class="canScrollRight ? 'hover:bg-white hover:bg-opacity-5 text-gray-300 hover:text-white' : 'text-white text-opacity-40 cursor-text'" @click="scrollRight">
|
|
|
|
<span class="material-icons" :style="{ fontSize: 1.5 + 'em' }">chevron_right</span>
|
2022-05-09 01:21:46 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
2024-06-03 08:04:03 +02:00
|
|
|
<div cy-id="slider" ref="slider" class="w-full overflow-y-hidden overflow-x-auto no-scroll" style="scroll-behavior: smooth" @scroll="scrolled">
|
2024-06-23 18:15:39 +02:00
|
|
|
<div class="flex space-x-4e">
|
2022-05-09 01:21:46 +02:00
|
|
|
<template v-for="(item, index) in items">
|
2024-06-03 08:04:03 +02:00
|
|
|
<div cy-id="item" ref="item" :key="itemKeyFunc(item)">
|
|
|
|
<component :is="componentName" :ref="itemRefFunc(item)" :index="index" :[itemPropName]="item" :bookshelf-view="bookshelfView" :continue-listening-shelf="continueListeningShelf" class="relative" @edit="editFunc" @editPodcast="editItem" @select="selectItem" @hook:updated="setScrollVars" />
|
|
|
|
</div>
|
2022-05-09 01:21:46 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
},
|
2022-05-10 01:23:23 +02:00
|
|
|
bookshelfView: {
|
|
|
|
type: Number,
|
|
|
|
default: 1
|
2022-09-29 00:45:39 +02:00
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
shelfId: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
continueListeningShelf: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
default: 'book'
|
|
|
|
}
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isScrollable: false,
|
|
|
|
canScrollLeft: false,
|
|
|
|
canScrollRight: false,
|
2024-06-03 08:04:03 +02:00
|
|
|
clientWidth: 0,
|
|
|
|
shelfOptionsByType: {
|
|
|
|
episode: {
|
|
|
|
component: 'cards-lazy-book-card',
|
|
|
|
itemPropName: 'book-mount',
|
|
|
|
itemIdFunc: (item) => item.recentEpisode.id
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
component: 'cards-lazy-series-card',
|
|
|
|
itemPropName: 'series-mount',
|
|
|
|
itemIdFunc: (item) => item.id
|
|
|
|
},
|
|
|
|
authors: {
|
|
|
|
component: 'cards-author-card',
|
|
|
|
itemPropName: 'author',
|
|
|
|
itemIdFunc: (item) => item.id
|
|
|
|
},
|
|
|
|
narrators: {
|
|
|
|
component: 'cards-narrator-card',
|
|
|
|
itemPropName: 'narrator',
|
|
|
|
itemIdFunc: (item) => item.name
|
|
|
|
},
|
|
|
|
book: {
|
|
|
|
component: 'cards-lazy-book-card',
|
|
|
|
itemPropName: 'book-mount',
|
|
|
|
itemIdFunc: (item) => item.id
|
|
|
|
},
|
|
|
|
podcast: {
|
|
|
|
component: 'cards-lazy-book-card',
|
|
|
|
itemPropName: 'book-mount',
|
|
|
|
itemIdFunc: (item) => item.id
|
|
|
|
}
|
2024-06-24 23:24:30 +02:00
|
|
|
}
|
2022-05-09 01:21:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2024-06-03 08:04:03 +02:00
|
|
|
isSelectionMode() {
|
|
|
|
return this.$store.getters['globals/getIsBatchSelectingMediaItems']
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
options() {
|
2024-06-24 23:24:30 +02:00
|
|
|
return this.shelfOptionsByType[this.type]
|
2022-05-10 01:23:23 +02:00
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
itemIdFunc() {
|
|
|
|
return this.options.itemIdFunc
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
itemKeyFunc() {
|
|
|
|
return (item) => this.itemIdFunc(item) + this.shelfId
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
itemRefFunc() {
|
|
|
|
return (item) => `slider-item-${this.itemIdFunc(item)}`
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
componentName() {
|
|
|
|
return this.options.component
|
|
|
|
},
|
|
|
|
itemPropName() {
|
|
|
|
return this.options.itemPropName
|
|
|
|
},
|
|
|
|
editFunc() {
|
|
|
|
switch (this.type) {
|
|
|
|
case 'episode':
|
|
|
|
return this.editEpisode
|
|
|
|
case 'authors':
|
|
|
|
return this.editAuthor
|
|
|
|
default:
|
|
|
|
return this.editItem
|
|
|
|
}
|
2022-05-09 01:21:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clearSelectedEntities() {
|
|
|
|
this.updateSelectionMode(false)
|
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
editEpisode({ libraryItem, episode }) {
|
|
|
|
this.$store.commit('setSelectedLibraryItem', libraryItem)
|
|
|
|
this.$store.commit('globals/setSelectedEpisode', episode)
|
|
|
|
this.$store.commit('globals/setShowEditPodcastEpisodeModal', true)
|
|
|
|
},
|
|
|
|
editAuthor(author) {
|
|
|
|
this.$store.commit('globals/showEditAuthorModal', author)
|
|
|
|
},
|
2022-05-09 01:21:46 +02:00
|
|
|
editItem(libraryItem) {
|
|
|
|
var itemIds = this.items.map((e) => e.id)
|
|
|
|
this.$store.commit('setBookshelfBookIds', itemIds)
|
|
|
|
this.$store.commit('showEditModal', libraryItem)
|
|
|
|
},
|
2022-10-16 00:17:40 +02:00
|
|
|
selectItem(payload) {
|
|
|
|
this.$emit('selectEntity', payload)
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
|
|
|
itemSelectedEvt() {
|
|
|
|
this.updateSelectionMode(this.isSelectionMode)
|
|
|
|
},
|
|
|
|
updateSelectionMode(val) {
|
2022-12-01 00:09:00 +01:00
|
|
|
const selectedMediaItems = this.$store.state.globals.selectedMediaItems
|
2022-05-09 01:21:46 +02:00
|
|
|
this.items.forEach((item) => {
|
2024-06-03 08:04:03 +02:00
|
|
|
let component = this.$refs[this.itemRefFunc(item)]
|
2022-05-09 01:21:46 +02:00
|
|
|
if (!component || !component.length) return
|
|
|
|
component = component[0]
|
|
|
|
component.setSelectionMode(val)
|
2022-12-01 00:09:00 +01:00
|
|
|
component.selected = selectedMediaItems.some((i) => i.id === item.id)
|
2022-05-09 01:21:46 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
scrolled() {
|
|
|
|
this.setScrollVars()
|
|
|
|
},
|
|
|
|
scrollRight() {
|
|
|
|
if (!this.canScrollRight) return
|
|
|
|
const slider = this.$refs.slider
|
|
|
|
if (!slider) return
|
2024-06-03 08:04:03 +02:00
|
|
|
const scrollAmount = this.clientWidth
|
2022-05-09 01:21:46 +02:00
|
|
|
const maxScrollLeft = slider.scrollWidth - slider.clientWidth
|
|
|
|
|
|
|
|
const newScrollLeft = Math.min(maxScrollLeft, slider.scrollLeft + scrollAmount)
|
|
|
|
slider.scrollLeft = newScrollLeft
|
|
|
|
},
|
|
|
|
scrollLeft() {
|
|
|
|
if (!this.canScrollLeft) return
|
|
|
|
const slider = this.$refs.slider
|
|
|
|
if (!slider) return
|
|
|
|
|
2024-06-03 08:04:03 +02:00
|
|
|
const scrollAmount = this.clientWidth
|
2022-05-09 01:21:46 +02:00
|
|
|
|
|
|
|
const newScrollLeft = Math.max(0, slider.scrollLeft - scrollAmount)
|
|
|
|
slider.scrollLeft = newScrollLeft
|
|
|
|
},
|
|
|
|
setScrollVars() {
|
|
|
|
const slider = this.$refs.slider
|
|
|
|
if (!slider) return
|
|
|
|
const { scrollLeft, scrollWidth, clientWidth } = slider
|
2024-06-03 08:04:03 +02:00
|
|
|
const scrollRemaining = Math.abs(scrollLeft + clientWidth - scrollWidth)
|
2022-05-09 01:21:46 +02:00
|
|
|
|
|
|
|
this.clientWidth = clientWidth
|
|
|
|
this.isScrollable = scrollWidth > clientWidth
|
2024-06-03 08:04:03 +02:00
|
|
|
this.canScrollRight = scrollRemaining >= 1
|
2022-05-09 01:21:46 +02:00
|
|
|
this.canScrollLeft = scrollLeft > 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
this.setScrollVars()
|
|
|
|
},
|
|
|
|
mounted() {
|
2024-06-03 08:04:03 +02:00
|
|
|
this.setScrollVars()
|
2024-06-24 23:37:02 +02:00
|
|
|
if (['book', 'podcast', 'episode'].includes(this.type)) {
|
|
|
|
this.$eventBus.$on('bookshelf_clear_selection', this.clearSelectedEntities)
|
|
|
|
this.$eventBus.$on('item-selected', this.itemSelectedEvt)
|
2024-06-03 08:04:03 +02:00
|
|
|
}
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2024-06-24 23:37:02 +02:00
|
|
|
if (['book', 'podcast', 'episode'].includes(this.type)) {
|
|
|
|
this.$eventBus.$off('bookshelf_clear_selection', this.clearSelectedEntities)
|
|
|
|
this.$eventBus.$off('item-selected', this.itemSelectedEvt)
|
2024-06-03 08:04:03 +02:00
|
|
|
}
|
2022-05-09 01:21:46 +02:00
|
|
|
}
|
|
|
|
}
|
2024-06-03 08:04:03 +02:00
|
|
|
</script>
|