Skip to content
Snippets Groups Projects
Show.vue 4.58 KiB
Newer Older
<!--
  - @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>
		<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" />
onny's avatar
onny committed
					v-show="!episodesLoaded"
					icon="icon-loading"
					class="tableLoading" />
		</transition>
</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: {
		MediaHeader,
		ShowEmpty,
		podcast: {
			episodes: [],
		},
		pageLoading: false,
onny's avatar
onny committed
		episodesLoaded: false,
	}),
	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 rect = document.getElementsByClassName('episodeTable')[0].getBoundingClientRect()
			console.log(rect.top, rect.right, rect.bottom, rect.left)

			const contentHeight = document.getElementById('app-content-vue').scrollHeight
			const tableHeight = height
onny's avatar
onny committed
			console.log(tableHeight, contentHeight)
			if (tableHeight < contentHeight) {
				this.preFill()
			}
		},

		doPlay(episode) {
			doPlay(episode)
		},

			console.log('prefilling')
			const podcastId = this.$route.params.id
			// this.queryPodcast(podcastId)
			console.log(podcastId)
		},

		/**
			 * 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) {
onny's avatar
onny committed
			if (podcast.meta.paging.page === 0) {
				this.podcast = podcast.data
onny's avatar
onny committed
			} 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) {
onny's avatar
onny committed
					if (!this.episodesLoaded) {
						const podcastId = this.$route.params.id
						this.queryPodcast(podcastId)
					}
.empty-content.tableLoading {
	margin-top: 10px !important;

	.empty-content__icon {
		margin-bottom: 0px !important;
	}
}