<!-- - @copyright Copyright (c) 2020 Jonas Heinrich - - @author Jonas Heinrich <onny@project-insanity.org> - - @license GNU AGPL version 3 or any later version - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - --> <template> <div> <ShowEmpty v-show="pageLoading" /> <transition name="fade"> <div v-show="!pageLoading"> <MediaHeader :imgurl="podcast.smallImageURL" :title="podcast.title" :author="podcast.author" :html-url="podcast.htmlURL" :categories="podcast.categories" :description="podcast.description" /> <Table v-resize="onResize" :episodes="podcast.episodes" @doPlay="doPlay" /> <EmptyContent v-show="!episodesLoaded" icon="icon-loading" /> </div> </transition> </div> </template> <script> import Table from '../components/Table' import MediaHeader from '../components/MediaHeader' import { showError } from '@nextcloud/dialogs' import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent' import axios from '@nextcloud/axios' import { audioPlayer, doPlay } from '../services/player' import ShowEmpty from './ShowEmpty' export default { name: 'Show', components: { EmptyContent, Table, MediaHeader, ShowEmpty, }, data: () => ({ podcast: { episodes: [], }, pageLoading: false, episodesLoaded: false, nextPage: null, }), computed: { player() { return this.$store.state.player }, }, watch: { $route: 'onRoute', 'player.volume'(newVolume, oldVolume) { if (audioPlayer !== null) { audioPlayer.volume(newVolume) } }, 'player.isPaused'(newState, oldState) { if (newState === true && audioPlayer !== null) { audioPlayer.pause() } else if (newState === false && audioPlayer !== null) { audioPlayer.play() } }, }, mounted() { this.pageLoading = true const podcastId = this.$route.params.id this.queryPodcast(podcastId) this.scroll() }, methods: { onResize({ width, height }) { const contentHeight = document.getElementById('app-content-vue').scrollHeight const tableHeight = height if (tableHeight < contentHeight) { this.preFill() } }, doPlay(episode) { doPlay(episode) }, preFill() { const route = this.$route console.log(route) // this.queryPodcast(route.name) }, /** * Start playing a podcast episode * @param {Object} episode Episode object */ async queryPodcast(podcastId) { const vm = this const queryURI = 'https://api.fyyd.de/0.2/podcast/episodes' try { delete axios.defaults.headers.requesttoken await axios.get(queryURI, { params: { podcast_id: podcastId, count: 20, page: vm.nextPage, }, }) .then(function(response) { vm.nextPage = response.data.meta.paging.next_page vm.processPodcast(response.data) }) } catch (error) { showError(t('podcast', 'Could not fetch stations from remote API')) } }, processPodcast(podcast) { if (podcast.meta.paging.page === 0) { this.podcast = podcast.data } else { if (podcast.meta.paging.page === podcast.meta.paging.last_page) { this.episodesLoaded = true } this.podcast.episodes = this.podcast.episodes.concat(podcast.data.episodes) } this.pageLoading = false }, /** * On scroll event, load more stations if bottom reached */ scroll() { window.onscroll = () => { if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { if (!this.episodesLoaded) { const podcastId = this.$route.params.id this.queryPodcast(podcastId) } } } }, }, } </script> <style lang="scss"> .empty-content { margin-top: 10px !important; .empty-content__icon { margin-bottom: 0px !important; } } </style>