2022-03-27 22:37:04 +02:00
|
|
|
<template>
|
|
|
|
<modals-modal v-model="show" name="podcast-episode-edit-modal" :width="800" :height="'unset'" :processing="processing">
|
|
|
|
<template #outer>
|
|
|
|
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
|
2023-02-11 22:02:56 +01:00
|
|
|
<p class="text-3xl text-white truncate">{{ title }}</p>
|
2022-03-27 22:37:04 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
2022-07-31 20:12:37 +02:00
|
|
|
<div class="absolute -top-10 left-0 z-10 w-full flex">
|
|
|
|
<template v-for="tab in tabs">
|
2023-02-11 22:02:56 +01:00
|
|
|
<div :key="tab.id" class="w-28 rounded-t-lg flex items-center justify-center mr-0.5 sm:mr-1 cursor-pointer hover:bg-bg border-t border-l border-r border-black-300 tab text-xs sm:text-base" :class="selectedTab === tab.id ? 'tab-selected bg-bg pb-px' : 'bg-primary text-gray-400'" @click="selectTab(tab.id)">{{ tab.title }}</div>
|
2022-07-31 20:12:37 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
|
2023-03-04 20:04:55 +01: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="goPrevEpisode" @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="goNextEpisode" @mousedown.prevent>arrow_forward_ios</div>
|
|
|
|
</div>
|
|
|
|
|
2022-07-31 20:12:37 +02:00
|
|
|
<div ref="wrapper" class="p-4 w-full text-sm rounded-b-lg rounded-tr-lg bg-bg shadow-lg border border-black-300 relative overflow-y-auto" style="max-height: 80vh">
|
2023-03-04 20:04:55 +01:00
|
|
|
<component v-if="libraryItem && show" :is="tabComponentName" :library-item="libraryItem" :episode="episodeItem" :processing.sync="processing" @close="show = false" @selectTab="selectTab" />
|
2022-03-27 22:37:04 +02:00
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2023-03-04 20:04:55 +01:00
|
|
|
episodeItem: null,
|
2022-03-27 22:37:04 +02:00
|
|
|
processing: false,
|
2022-07-31 20:12:37 +02:00
|
|
|
tabs: [
|
|
|
|
{
|
|
|
|
id: 'details',
|
2022-11-09 00:10:08 +01:00
|
|
|
title: this.$strings.HeaderDetails,
|
2022-07-31 20:12:37 +02:00
|
|
|
component: 'modals-podcast-tabs-episode-details'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'match',
|
2022-11-09 00:10:08 +01:00
|
|
|
title: this.$strings.HeaderMatch,
|
2022-07-31 20:12:37 +02:00
|
|
|
component: 'modals-podcast-tabs-episode-match'
|
|
|
|
}
|
|
|
|
]
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
},
|
2023-03-04 20:04:55 +01:00
|
|
|
watch: {
|
|
|
|
show: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
2023-03-05 19:28:20 +01:00
|
|
|
const availableTabIds = this.tabs.map((tab) => tab.id)
|
2023-03-04 20:04:55 +01:00
|
|
|
if (!availableTabIds.length) {
|
|
|
|
this.show = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!availableTabIds.includes(this.selectedTab)) {
|
|
|
|
this.selectedTab = availableTabIds[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
this.episodeItem = null
|
|
|
|
this.init()
|
|
|
|
this.registerListeners()
|
|
|
|
} else {
|
|
|
|
this.unregisterListeners()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
2022-04-23 02:31:11 +02:00
|
|
|
return this.$store.state.globals.showEditPodcastEpisode
|
2022-03-27 22:37:04 +02:00
|
|
|
},
|
|
|
|
set(val) {
|
2022-04-23 02:31:11 +02:00
|
|
|
this.$store.commit('globals/setShowEditPodcastEpisodeModal', val)
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
},
|
2023-03-04 20:04:55 +01:00
|
|
|
selectedTab: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state.editPodcastModalTab
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$store.commit('setEditPodcastModalTab', val)
|
|
|
|
}
|
|
|
|
},
|
2022-04-23 02:31:11 +02:00
|
|
|
libraryItem() {
|
|
|
|
return this.$store.state.selectedLibraryItem
|
|
|
|
},
|
|
|
|
episode() {
|
|
|
|
return this.$store.state.globals.selectedEpisode
|
|
|
|
},
|
2023-03-04 20:04:55 +01:00
|
|
|
selectedEpisodeId() {
|
|
|
|
return this.episode.id
|
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
title() {
|
2023-03-05 19:28:20 +01:00
|
|
|
return this.libraryItem?.media.metadata.title || 'Unknown'
|
2022-07-31 20:12:37 +02:00
|
|
|
},
|
|
|
|
tabComponentName() {
|
2023-03-05 19:28:20 +01:00
|
|
|
const _tab = this.tabs.find((t) => t.id === this.selectedTab)
|
2022-07-31 20:12:37 +02:00
|
|
|
return _tab ? _tab.component : ''
|
2023-03-04 20:04:55 +01:00
|
|
|
},
|
|
|
|
episodeTableEpisodeIds() {
|
|
|
|
return this.$store.state.episodeTableEpisodeIds || []
|
|
|
|
},
|
|
|
|
currentEpisodeIndex() {
|
|
|
|
if (!this.episodeTableEpisodeIds.length) return 0
|
|
|
|
return this.episodeTableEpisodeIds.findIndex((bid) => bid === this.selectedEpisodeId)
|
|
|
|
},
|
|
|
|
canGoPrev() {
|
|
|
|
return this.episodeTableEpisodeIds.length && this.currentEpisodeIndex > 0
|
|
|
|
},
|
|
|
|
canGoNext() {
|
|
|
|
return this.episodeTableEpisodeIds.length && this.currentEpisodeIndex < this.episodeTableEpisodeIds.length - 1
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-03-04 20:04:55 +01:00
|
|
|
async goPrevEpisode() {
|
|
|
|
if (this.currentEpisodeIndex - 1 < 0) return
|
2023-03-05 19:28:20 +01:00
|
|
|
const prevEpisodeId = this.episodeTableEpisodeIds[this.currentEpisodeIndex - 1]
|
2023-03-04 20:04:55 +01:00
|
|
|
this.processing = true
|
|
|
|
const prevEpisode = await this.$axios.$get(`/api/podcasts/${this.libraryItem.id}/episode/${prevEpisodeId}`).catch((error) => {
|
2023-03-05 19:28:20 +01:00
|
|
|
const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch episode'
|
2023-03-04 20:04:55 +01:00
|
|
|
this.$toast.error(errorMsg)
|
|
|
|
return null
|
2023-03-05 19:28:20 +01:00
|
|
|
})
|
2023-03-04 20:04:55 +01:00
|
|
|
this.processing = false
|
|
|
|
if (prevEpisode) {
|
|
|
|
this.episodeItem = prevEpisode
|
|
|
|
this.$store.commit('globals/setSelectedEpisode', prevEpisode)
|
|
|
|
} else {
|
|
|
|
console.error('Episode not found', prevEpisodeId)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async goNextEpisode() {
|
|
|
|
if (this.currentEpisodeIndex >= this.episodeTableEpisodeIds.length - 1) return
|
|
|
|
this.processing = true
|
2023-03-05 19:28:20 +01:00
|
|
|
const nextEpisodeId = this.episodeTableEpisodeIds[this.currentEpisodeIndex + 1]
|
2023-03-04 20:04:55 +01:00
|
|
|
const nextEpisode = await this.$axios.$get(`/api/podcasts/${this.libraryItem.id}/episode/${nextEpisodeId}`).catch((error) => {
|
2023-03-05 19:28:20 +01:00
|
|
|
const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch book'
|
2023-03-04 20:04:55 +01:00
|
|
|
this.$toast.error(errorMsg)
|
|
|
|
return null
|
2023-03-05 19:28:20 +01:00
|
|
|
})
|
2023-03-04 20:04:55 +01:00
|
|
|
this.processing = false
|
|
|
|
if (nextEpisode) {
|
|
|
|
this.episodeItem = nextEpisode
|
|
|
|
this.$store.commit('globals/setSelectedEpisode', nextEpisode)
|
|
|
|
} else {
|
|
|
|
console.error('Episode not found', nextEpisodeId)
|
|
|
|
}
|
|
|
|
},
|
2022-07-31 20:12:37 +02:00
|
|
|
selectTab(tab) {
|
2023-03-04 20:04:55 +01:00
|
|
|
if (this.selectedTab === tab) return
|
|
|
|
if (this.tabs.find((t) => t.id === tab)) {
|
|
|
|
this.selectedTab = tab
|
|
|
|
this.processing = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
init() {
|
|
|
|
this.fetchFull()
|
|
|
|
},
|
|
|
|
async fetchFull() {
|
|
|
|
try {
|
|
|
|
this.processing = true
|
|
|
|
this.episodeItem = await this.$axios.$get(`/api/podcasts/${this.libraryItem.id}/episode/${this.selectedEpisodeId}`)
|
|
|
|
this.processing = false
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to fetch episode', this.selectedEpisodeId, error)
|
|
|
|
this.processing = false
|
|
|
|
this.show = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hotkey(action) {
|
|
|
|
if (action === this.$hotkeys.Modal.NEXT_PAGE) {
|
|
|
|
this.goNextEpisode()
|
|
|
|
} else if (action === this.$hotkeys.Modal.PREV_PAGE) {
|
|
|
|
this.goPrevEpisode()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
registerListeners() {
|
|
|
|
this.$eventBus.$on('modal-hotkey', this.hotkey)
|
|
|
|
},
|
|
|
|
unregisterListeners() {
|
|
|
|
this.$eventBus.$off('modal-hotkey', this.hotkey)
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
},
|
2023-03-04 20:04:55 +01:00
|
|
|
mounted() {},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.unregisterListeners()
|
|
|
|
}
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
</script>
|
2022-07-31 20:12:37 +02:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.tab {
|
|
|
|
height: 40px;
|
|
|
|
}
|
|
|
|
.tab.tab-selected {
|
|
|
|
height: 41px;
|
|
|
|
}
|
2023-03-04 20:04:55 +01:00
|
|
|
</style>
|