Remove library item listener from edit episode modal

This commit is contained in:
advplyr 2023-03-05 12:28:20 -06:00
parent 72396c5a98
commit dccad3055b
4 changed files with 21 additions and 36 deletions

View File

@ -48,7 +48,7 @@ export default {
show: { show: {
handler(newVal) { handler(newVal) {
if (newVal) { if (newVal) {
const availableTabIds = this.tabs.map((tab) => tab.id); const availableTabIds = this.tabs.map((tab) => tab.id)
if (!availableTabIds.length) { if (!availableTabIds.length) {
this.show = false this.show = false
return return
@ -94,11 +94,10 @@ export default {
return this.episode.id return this.episode.id
}, },
title() { title() {
if (!this.libraryItem) return '' return this.libraryItem?.media.metadata.title || 'Unknown'
return this.libraryItem.media.metadata.title || 'Unknown'
}, },
tabComponentName() { tabComponentName() {
const _tab = this.tabs.find((t) => t.id === this.selectedTab); const _tab = this.tabs.find((t) => t.id === this.selectedTab)
return _tab ? _tab.component : '' return _tab ? _tab.component : ''
}, },
episodeTableEpisodeIds() { episodeTableEpisodeIds() {
@ -118,19 +117,17 @@ export default {
methods: { methods: {
async goPrevEpisode() { async goPrevEpisode() {
if (this.currentEpisodeIndex - 1 < 0) return if (this.currentEpisodeIndex - 1 < 0) return
const prevEpisodeId = this.episodeTableEpisodeIds[this.currentEpisodeIndex - 1]; const prevEpisodeId = this.episodeTableEpisodeIds[this.currentEpisodeIndex - 1]
this.processing = true this.processing = true
const prevEpisode = await this.$axios.$get(`/api/podcasts/${this.libraryItem.id}/episode/${prevEpisodeId}`).catch((error) => { const prevEpisode = await this.$axios.$get(`/api/podcasts/${this.libraryItem.id}/episode/${prevEpisodeId}`).catch((error) => {
const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch episode'; const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch episode'
this.$toast.error(errorMsg) this.$toast.error(errorMsg)
return null return null
}); })
this.processing = false this.processing = false
if (prevEpisode) { if (prevEpisode) {
this.unregisterListeners()
this.episodeItem = prevEpisode this.episodeItem = prevEpisode
this.$store.commit('globals/setSelectedEpisode', prevEpisode) this.$store.commit('globals/setSelectedEpisode', prevEpisode)
this.$nextTick(this.registerListeners)
} else { } else {
console.error('Episode not found', prevEpisodeId) console.error('Episode not found', prevEpisodeId)
} }
@ -138,18 +135,16 @@ export default {
async goNextEpisode() { async goNextEpisode() {
if (this.currentEpisodeIndex >= this.episodeTableEpisodeIds.length - 1) return if (this.currentEpisodeIndex >= this.episodeTableEpisodeIds.length - 1) return
this.processing = true this.processing = true
const nextEpisodeId = this.episodeTableEpisodeIds[this.currentEpisodeIndex + 1]; const nextEpisodeId = this.episodeTableEpisodeIds[this.currentEpisodeIndex + 1]
const nextEpisode = await this.$axios.$get(`/api/podcasts/${this.libraryItem.id}/episode/${nextEpisodeId}`).catch((error) => { const nextEpisode = await this.$axios.$get(`/api/podcasts/${this.libraryItem.id}/episode/${nextEpisodeId}`).catch((error) => {
const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch book'; const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to fetch book'
this.$toast.error(errorMsg) this.$toast.error(errorMsg)
return null return null
}); })
this.processing = false this.processing = false
if (nextEpisode) { if (nextEpisode) {
this.unregisterListeners()
this.episodeItem = nextEpisode this.episodeItem = nextEpisode
this.$store.commit('globals/setSelectedEpisode', nextEpisode) this.$store.commit('globals/setSelectedEpisode', nextEpisode)
this.$nextTick(this.registerListeners)
} else { } else {
console.error('Episode not found', nextEpisodeId) console.error('Episode not found', nextEpisodeId)
} }
@ -161,9 +156,6 @@ export default {
this.processing = false this.processing = false
} }
}, },
libraryItemUpdated(expandedLibraryItem) {
this.libraryItem = expandedLibraryItem
},
init() { init() {
this.fetchFull() this.fetchFull()
}, },
@ -187,11 +179,9 @@ export default {
}, },
registerListeners() { registerListeners() {
this.$eventBus.$on('modal-hotkey', this.hotkey) this.$eventBus.$on('modal-hotkey', this.hotkey)
this.$eventBus.$on(`${this.selectedLibraryItemId}_updated`, this.libraryItemUpdated)
}, },
unregisterListeners() { unregisterListeners() {
this.$eventBus.$off('modal-hotkey', this.hotkey) this.$eventBus.$off('modal-hotkey', this.hotkey)
this.$eventBus.$off(`${this.selectedLibraryItemId}_updated`, this.libraryItemUpdated)
} }
}, },
mounted() {}, mounted() {},

View File

@ -148,15 +148,12 @@ export default {
}, },
async updateDetails(updatedDetails) { async updateDetails(updatedDetails) {
this.isProcessing = true this.isProcessing = true
const updateResult = await this.$axios const updateResult = await this.$axios.$patch(`/api/podcasts/${this.libraryItem.id}/episode/${this.episodeId}`, updatedDetails).catch((error) => {
.$patch(`/api/podcasts/${this.libraryItem.id}/episode/${this.episodeId}`, updatedDetails) console.error('Failed update episode', error)
.catch((error) => { this.isProcessing = false
const errorMsg = error.response && error.response.data ? error.response.data : 'Failed to update episode'; this.$toast.error(error?.response?.data || 'Failed to update episode')
console.error('Failed update episode', error) return false
this.isProcessing = false })
this.$toast.error(errorMsg)
return false
});
this.isProcessing = false this.isProcessing = false
if (updateResult) { if (updateResult) {

View File

@ -68,8 +68,6 @@ export default {
} }
}, },
mounted() {}, mounted() {},
beforeDestroy() { beforeDestroy() {}
console.log('Before destroy')
}
} }
</script> </script>

View File

@ -227,13 +227,13 @@ class PodcastController {
// GET: api/podcasts/:id/episode/:episodeId // GET: api/podcasts/:id/episode/:episodeId
async getEpisode(req, res) { async getEpisode(req, res) {
const episodeId = req.params.episodeId; const episodeId = req.params.episodeId
const libraryItem = req.libraryItem; const libraryItem = req.libraryItem
const episode = libraryItem.media.episodes.find(ep => ep.id === episodeId); const episode = libraryItem.media.episodes.find(ep => ep.id === episodeId)
if (!episode) { if (!episode) {
Logger.error(`[PodcastController] getEpisode episode ${episodeId} not found for item ${libraryItem.id}`) Logger.error(`[PodcastController] getEpisode episode ${episodeId} not found for item ${libraryItem.id}`)
return res.sendStatus(404) return res.sendStatus(404)
} }
res.json(episode) res.json(episode)