2022-12-03 12:06:24 -06:00
|
|
|
<template>
|
2022-12-03 17:24:24 -06:00
|
|
|
<div class="w-full p-4">
|
2023-12-03 17:37:01 -06:00
|
|
|
<h1 class="text-xl mb-2 font-semibold">{{ $strings.HeaderLatestEpisodes }}</h1>
|
2022-12-03 17:24:24 -06:00
|
|
|
|
|
|
|
<template v-for="episode in recentEpisodes">
|
2023-01-30 11:39:01 -06:00
|
|
|
<tables-podcast-latest-episode-row :episode="episode" :local-episode="localEpisodeMap[episode.id]" :library-item-id="episode.libraryItemId" :local-library-item-id="null" :is-local="isLocal" :key="episode.id" @addToPlaylist="addEpisodeToPlaylist" />
|
2022-12-03 17:24:24 -06:00
|
|
|
</template>
|
|
|
|
</div>
|
2022-12-03 12:06:24 -06:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
2022-12-03 17:24:24 -06:00
|
|
|
return {
|
|
|
|
processing: false,
|
|
|
|
recentEpisodes: [],
|
|
|
|
totalEpisodes: 0,
|
|
|
|
currentPage: 0,
|
2023-12-09 14:57:44 -06:00
|
|
|
localLibraryItems: [],
|
2023-03-05 11:12:17 -06:00
|
|
|
isLocal: false,
|
|
|
|
loadedLibraryId: null
|
2022-12-03 17:24:24 -06:00
|
|
|
}
|
2022-12-03 12:06:24 -06:00
|
|
|
},
|
|
|
|
watch: {},
|
2022-12-03 17:24:24 -06:00
|
|
|
computed: {
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
2023-12-09 14:57:44 -06:00
|
|
|
},
|
|
|
|
localEpisodes() {
|
|
|
|
const episodes = []
|
|
|
|
this.localLibraryItems.forEach((li) => {
|
|
|
|
if (li.media.episodes?.length) {
|
|
|
|
episodes.push(...li.media.episodes)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return episodes
|
|
|
|
},
|
|
|
|
localEpisodeMap() {
|
|
|
|
var epmap = {}
|
|
|
|
this.localEpisodes.forEach((localEp) => {
|
|
|
|
if (localEp.serverEpisodeId) {
|
|
|
|
epmap[localEp.serverEpisodeId] = localEp
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return epmap
|
2022-12-03 17:24:24 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async addEpisodeToPlaylist(episode) {
|
2023-09-15 17:35:44 -05:00
|
|
|
const libraryItem = await this.$nativeHttp.get(`/api/items/${episode.libraryItemId}`).catch((error) => {
|
2022-12-03 17:24:24 -06:00
|
|
|
console.error('Failed to get library item', error)
|
|
|
|
this.$toast.error('Failed to get library item')
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
if (!libraryItem) return
|
|
|
|
|
|
|
|
this.$store.commit('globals/setSelectedPlaylistItems', [{ libraryItem, episode }])
|
|
|
|
this.$store.commit('globals/setShowPlaylistsAddCreateModal', true)
|
|
|
|
},
|
|
|
|
async loadRecentEpisodes(page = 0) {
|
2023-03-05 11:12:17 -06:00
|
|
|
this.loadedLibraryId = this.currentLibraryId
|
2022-12-03 17:24:24 -06:00
|
|
|
this.processing = true
|
2023-09-15 17:35:44 -05:00
|
|
|
const episodePayload = await this.$nativeHttp.get(`/api/libraries/${this.currentLibraryId}/recent-episodes?limit=25&page=${page}`).catch((error) => {
|
2022-12-03 17:24:24 -06:00
|
|
|
console.error('Failed to get recent episodes', error)
|
|
|
|
this.$toast.error('Failed to get recent episodes')
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
this.processing = false
|
|
|
|
console.log('Episodes', episodePayload)
|
|
|
|
this.recentEpisodes = episodePayload.episodes || []
|
|
|
|
this.totalEpisodes = episodePayload.total
|
|
|
|
this.currentPage = page
|
2023-03-05 11:12:17 -06:00
|
|
|
},
|
|
|
|
libraryChanged(libraryId) {
|
|
|
|
if (libraryId !== this.loadedLibraryId) {
|
|
|
|
if (this.$store.getters['libraries/getCurrentLibraryMediaType'] === 'podcast') {
|
|
|
|
this.loadRecentEpisodes()
|
|
|
|
} else {
|
|
|
|
this.$router.replace('/bookshelf')
|
|
|
|
}
|
|
|
|
}
|
2023-12-09 14:57:44 -06:00
|
|
|
},
|
|
|
|
async loadLocalPodcastLibraryItems() {
|
|
|
|
this.localLibraryItems = await this.$db.getLocalLibraryItems('podcast')
|
|
|
|
},
|
|
|
|
newLocalLibraryItem(item) {
|
|
|
|
if (item.mediaType !== 'podcast') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const matchingLocalLibraryItem = this.localLibraryItems.find((lli) => lli.id === item.id)
|
|
|
|
if (matchingLocalLibraryItem) {
|
|
|
|
matchingLocalLibraryItem.media.episodes = item.media.episodes
|
|
|
|
} else {
|
|
|
|
this.localLibraryItems.push(item)
|
|
|
|
}
|
2022-12-03 17:24:24 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.loadRecentEpisodes()
|
2023-12-09 14:57:44 -06:00
|
|
|
this.loadLocalPodcastLibraryItems()
|
2023-03-05 11:12:17 -06:00
|
|
|
this.$eventBus.$on('library-changed', this.libraryChanged)
|
2023-12-09 14:57:44 -06:00
|
|
|
this.$eventBus.$on('new-local-library-item', this.newLocalLibraryItem)
|
2023-03-05 11:12:17 -06:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$eventBus.$off('library-changed', this.libraryChanged)
|
2023-12-09 14:57:44 -06:00
|
|
|
this.$eventBus.$off('new-local-library-item', this.newLocalLibraryItem)
|
2022-12-03 17:24:24 -06:00
|
|
|
}
|
2022-12-03 12:06:24 -06:00
|
|
|
}
|
|
|
|
</script>
|