2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2021-09-05 02:58:39 +02:00
|
|
|
<modals-modal v-model="show" :width="800" :height="height" :processing="processing" :content-margin-top="75">
|
2021-08-18 00:01:11 +02:00
|
|
|
<template #outer>
|
|
|
|
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
|
|
|
|
<p class="font-book text-3xl text-white truncate">{{ title }}</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div class="absolute -top-10 left-0 w-full flex">
|
2021-09-07 00:42:15 +02:00
|
|
|
<template v-for="tab in availableTabs">
|
2021-09-04 21:17:26 +02:00
|
|
|
<div :key="tab.id" class="w-28 rounded-t-lg flex items-center justify-center mr-1 cursor-pointer hover:bg-bg font-book border-t border-l border-r border-black-300 tab" :class="selectedTab === tab.id ? 'tab-selected bg-bg pb-px' : 'bg-primary text-gray-400'" @click="selectTab(tab.id)">{{ tab.title }}</div>
|
|
|
|
</template>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
2021-10-16 03:31:00 +02:00
|
|
|
|
|
|
|
<div v-show="canGoPrev" class="absolute -left-24 top-0 bottom-0 h-full pointer-events-none flex items-center px-6">
|
|
|
|
<div class="material-icons text-5xl text-white text-opacity-50 hover:text-opacity-90 cursor-pointer pointer-events-auto" @click.stop.prevent="goPrevBook" @mousedown.prevent>arrow_back_ios</div>
|
|
|
|
</div>
|
|
|
|
<div v-show="canGoNext" class="absolute -right-24 top-0 bottom-0 h-full pointer-events-none flex items-center px-6">
|
|
|
|
<div class="material-icons text-5xl text-white text-opacity-50 hover:text-opacity-90 cursor-pointer pointer-events-auto" @click.stop.prevent="goNextBook" @mousedown.prevent>arrow_forward_ios</div>
|
|
|
|
</div>
|
|
|
|
|
2021-09-06 21:13:01 +02:00
|
|
|
<div class="w-full h-full text-sm rounded-b-lg rounded-tr-lg bg-bg shadow-lg border border-black-300">
|
2021-08-18 00:01:11 +02:00
|
|
|
<keep-alive>
|
|
|
|
<component v-if="audiobook" :is="tabName" :audiobook="audiobook" :processing.sync="processing" @close="show = false" />
|
|
|
|
</keep-alive>
|
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
processing: false,
|
2021-08-26 02:15:00 +02:00
|
|
|
audiobook: null,
|
2021-09-04 21:17:26 +02:00
|
|
|
fetchOnShow: false,
|
|
|
|
tabs: [
|
|
|
|
{
|
|
|
|
id: 'details',
|
|
|
|
title: 'Details',
|
|
|
|
component: 'modals-edit-tabs-details'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'cover',
|
|
|
|
title: 'Cover',
|
|
|
|
component: 'modals-edit-tabs-cover'
|
|
|
|
},
|
2021-10-09 00:51:09 +02:00
|
|
|
// {
|
|
|
|
// id: 'match',
|
|
|
|
// title: 'Match',
|
|
|
|
// component: 'modals-edit-tabs-match'
|
|
|
|
// },
|
2021-09-04 21:17:26 +02:00
|
|
|
{
|
|
|
|
id: 'tracks',
|
|
|
|
title: 'Tracks',
|
|
|
|
component: 'modals-edit-tabs-tracks'
|
|
|
|
},
|
2021-09-08 16:15:54 +02:00
|
|
|
{
|
|
|
|
id: 'chapters',
|
|
|
|
title: 'Chapters',
|
|
|
|
component: 'modals-edit-tabs-chapters'
|
|
|
|
},
|
2021-10-16 03:31:00 +02:00
|
|
|
{
|
|
|
|
id: 'files',
|
|
|
|
title: 'Files',
|
|
|
|
component: 'modals-edit-tabs-files'
|
|
|
|
},
|
2021-09-04 21:17:26 +02:00
|
|
|
{
|
|
|
|
id: 'download',
|
|
|
|
title: 'Download',
|
|
|
|
component: 'modals-edit-tabs-download'
|
|
|
|
}
|
|
|
|
]
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
show: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
2021-09-07 00:42:15 +02:00
|
|
|
var availableTabIds = this.availableTabs.map((tab) => tab.id)
|
|
|
|
if (!availableTabIds.length) {
|
|
|
|
this.show = false
|
|
|
|
return
|
|
|
|
}
|
2021-10-16 03:31:00 +02:00
|
|
|
|
2021-09-07 00:42:15 +02:00
|
|
|
if (!availableTabIds.includes(this.selectedTab)) {
|
|
|
|
this.selectedTab = availableTabIds[0]
|
|
|
|
}
|
|
|
|
|
2021-08-26 02:15:00 +02:00
|
|
|
if (this.audiobook && this.audiobook.id === this.selectedAudiobookId) {
|
|
|
|
if (this.fetchOnShow) this.fetchFull()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.fetchOnShow = false
|
2021-08-18 00:01:11 +02:00
|
|
|
this.audiobook = null
|
2021-08-21 16:15:44 +02:00
|
|
|
this.init()
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state.showEditModal
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$store.commit('setShowEditModal', val)
|
|
|
|
}
|
|
|
|
},
|
2021-09-06 21:13:01 +02:00
|
|
|
selectedTab: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state.editModalTab
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$store.commit('setEditModalTab', val)
|
|
|
|
}
|
|
|
|
},
|
2021-09-07 00:42:15 +02:00
|
|
|
userCanUpdate() {
|
|
|
|
return this.$store.getters['user/getUserCanUpdate']
|
|
|
|
},
|
|
|
|
userCanDownload() {
|
|
|
|
return this.$store.getters['user/getUserCanDownload']
|
|
|
|
},
|
|
|
|
availableTabs() {
|
|
|
|
if (!this.userCanUpdate && !this.userCanDownload) return []
|
|
|
|
return this.tabs.filter((tab) => {
|
2021-09-18 01:40:30 +02:00
|
|
|
if (tab.id === 'download' && this.isMissing) return false
|
2021-09-07 00:42:15 +02:00
|
|
|
if ((tab.id === 'download' || tab.id === 'tracks') && this.userCanDownload) return true
|
|
|
|
if (tab.id !== 'download' && tab.id !== 'tracks' && this.userCanUpdate) return true
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
},
|
2021-09-05 02:58:39 +02:00
|
|
|
height() {
|
|
|
|
var maxHeightAllowed = window.innerHeight - 150
|
|
|
|
return Math.min(maxHeightAllowed, 650)
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
tabName() {
|
2021-09-04 21:17:26 +02:00
|
|
|
var _tab = this.tabs.find((t) => t.id === this.selectedTab)
|
|
|
|
return _tab ? _tab.component : ''
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-09-18 01:40:30 +02:00
|
|
|
isMissing() {
|
|
|
|
return this.selectedAudiobook.isMissing
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
selectedAudiobook() {
|
|
|
|
return this.$store.state.selectedAudiobook || {}
|
|
|
|
},
|
|
|
|
selectedAudiobookId() {
|
|
|
|
return this.selectedAudiobook.id
|
|
|
|
},
|
|
|
|
book() {
|
|
|
|
return this.audiobook ? this.audiobook.book || {} : {}
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
return this.book.title || 'No Title'
|
2021-10-16 03:31:00 +02:00
|
|
|
},
|
|
|
|
bookshelfBookIds() {
|
|
|
|
return this.$store.state.bookshelfBookIds || []
|
|
|
|
},
|
|
|
|
currentBookshelfIndex() {
|
|
|
|
if (!this.bookshelfBookIds.length) return 0
|
|
|
|
return this.bookshelfBookIds.findIndex((bid) => bid === this.selectedAudiobookId)
|
|
|
|
},
|
|
|
|
canGoPrev() {
|
|
|
|
return this.bookshelfBookIds.length && this.currentBookshelfIndex > 0
|
|
|
|
},
|
|
|
|
canGoNext() {
|
|
|
|
return this.bookshelfBookIds.length && this.currentBookshelfIndex < this.bookshelfBookIds.length - 1
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-16 03:31:00 +02:00
|
|
|
goPrevBook() {
|
|
|
|
if (this.currentBookshelfIndex - 1 < 0) return
|
|
|
|
var prevBookId = this.bookshelfBookIds[this.currentBookshelfIndex - 1]
|
|
|
|
var prevBook = this.$store.getters['audiobooks/getAudiobook'](prevBookId)
|
|
|
|
if (prevBook) {
|
|
|
|
this.$store.commit('showEditModalOnTab', { audiobook: prevBook, tab: this.selectedTab })
|
|
|
|
this.$nextTick(this.init)
|
|
|
|
} else {
|
|
|
|
console.error('Book not found', prevBookId)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
goNextBook() {
|
|
|
|
if (this.currentBookshelfIndex >= this.bookshelfBookIds.length) return
|
|
|
|
var nextBookId = this.bookshelfBookIds[this.currentBookshelfIndex + 1]
|
|
|
|
var nextBook = this.$store.getters['audiobooks/getAudiobook'](nextBookId)
|
|
|
|
if (nextBook) {
|
|
|
|
this.$store.commit('showEditModalOnTab', { audiobook: nextBook, tab: this.selectedTab })
|
|
|
|
this.$nextTick(this.init)
|
|
|
|
} else {
|
|
|
|
console.error('Book not found', nextBookId)
|
|
|
|
}
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
selectTab(tab) {
|
|
|
|
this.selectedTab = tab
|
|
|
|
},
|
2021-08-21 16:15:44 +02:00
|
|
|
audiobookUpdated() {
|
2021-08-26 02:15:00 +02:00
|
|
|
if (!this.show) this.fetchOnShow = true
|
|
|
|
else {
|
|
|
|
this.fetchFull()
|
|
|
|
}
|
2021-08-21 16:15:44 +02:00
|
|
|
},
|
|
|
|
init() {
|
|
|
|
this.$store.commit('audiobooks/addListener', { meth: this.audiobookUpdated, id: 'edit-modal', audiobookId: this.selectedAudiobookId })
|
|
|
|
this.fetchFull()
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
async fetchFull() {
|
|
|
|
try {
|
2021-10-16 03:31:00 +02:00
|
|
|
this.processing = true
|
2021-08-18 00:01:11 +02:00
|
|
|
this.audiobook = await this.$axios.$get(`/api/audiobook/${this.selectedAudiobookId}`)
|
2021-10-16 03:31:00 +02:00
|
|
|
this.processing = false
|
2021-08-18 00:01:11 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to fetch audiobook', this.selectedAudiobookId, error)
|
2021-10-16 03:31:00 +02:00
|
|
|
this.processing = false
|
2021-08-18 00:01:11 +02:00
|
|
|
this.show = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
2021-08-19 18:31:03 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.tab {
|
|
|
|
height: 40px;
|
|
|
|
}
|
|
|
|
.tab.tab-selected {
|
|
|
|
height: 41px;
|
|
|
|
}
|
|
|
|
</style>
|