Skip to content
Snippets Groups Projects
Show.vue 4.46 KiB
Newer Older
  - @copyright Copyright (c) 2021 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="loading" />
		<transition name="fade">
				<MediaHeader
					:imgurl="podcast.smallImageURL"
					:title="podcast.title"
					:author="podcast.author"
onny's avatar
onny committed
					:htmlurl="podcast.htmlURL"
					:categories="podcast.categories"
onny's avatar
onny committed
					:description="podcast.description"
					:podcastid="podcast.id"
					:isshow="true"
					@doSubscribe="doSubscribe" />
				<Table
					v-resize="onResize"
onny's avatar
onny committed
					:episodes="episodes"
					@doPlay="doPlay" />
onny's avatar
onny committed
					v-show="page"
					icon="icon-loading"
					class="tableLoading" />
		</transition>
</template>

<script>
import Table from '../components/Table'
import MediaHeader from '../components/MediaHeader'
import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent'
import ShowEmpty from './placeholder/Show'
onny's avatar
onny committed

onny's avatar
onny committed
import { FyydApi } from './../services/FyydApi'
onny's avatar
onny committed
const fyydClient = new FyydApi()
export default {
	name: 'Show',
	components: {
		MediaHeader,
		ShowEmpty,
onny's avatar
onny committed
		podcast: {},
		episodes: [],
		page: 0,
onny's avatar
onny committed
		loading: true,
onny's avatar
onny committed
		isSubscribed() {
			return this.$store.getters.showExists(this.podcastId)
		},
onny's avatar
onny committed
		'$route'(to, from) {
			this.podcastId = to.params.id
onny's avatar
onny committed
		},
onny's avatar
onny committed
		this.initPage()
	},
	destroyed() {
	  window.removeEventListener('scroll', this.handleScroll)
		isPlaying(episodeId) {
			return this.$store.getters.isPlaying(episodeId)
		},

onny's avatar
onny committed
		initPage() {
onny's avatar
onny committed
			this.podcast = {}
			this.episodes = []
			this.page = 0
			this.podcastId = this.$route.params.id
			window.addEventListener('scroll', this.handleScroll)
			this.queryPodcast(this.podcastId)
			this.queryEpisodes(this.podcastId, this.page)
		},

		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()
			}
		},

onny's avatar
onny committed
		doSubscribe() {
			if (this.isSubscribed) {
				this.$store.dispatch('removeShow', this.podcast)
			} else {
				this.$store.dispatch('addShow', this.podcast)
			console.log('prefilling')
			// this.queryPodcast(podcastId)
		},

		async queryPodcast(podcastId) {
onny's avatar
onny committed
			const podcast = await fyydClient.queryPodcast(podcastId)
			this.processPodcast(podcast.data)
onny's avatar
onny committed
		async queryEpisodes(podcastId, page) {
			const episodes = await fyydClient.queryEpisodes(podcastId, page)
			this.episodes = this.episodes.concat(episodes.data.episodes)
			if (episodes.meta.paging.next_page === null) {
				this.page = null
				window.removeEventListener('scroll', this.handleScroll)
			} else {
onny's avatar
onny committed
				this.page += 1
onny's avatar
onny committed
		},

		processPodcast(podcast) {
			this.podcast = podcast
			document.title = podcast.title + ' - Podcast - Nextcloud'
onny's avatar
onny committed
			this.loading = false
		 * On scroll event, load more episodes if bottom reached
		handleScroll() {
			if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
				if (!this.episodesLoaded) {
onny's avatar
onny committed
					this.queryEpisodes(this.podcastId, this.page)
onny's avatar
onny committed

		doPlay(episode) {
			if (this.isPlaying(episode.id)) {
				this.$store.dispatch('pauseEpisode')
			} else {
				this.$store.dispatch('playEpisode', episode)
			}
onny's avatar
onny committed
		},
.empty-content.tableLoading {
	margin-top: 10px !important;

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