1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-17 07:40:27 +05:30
Piped/src/components/Playlist.vue
2022-01-12 05:31:12 +00:00

91 lines
3.0 KiB
Vue

<template>
<ErrorHandler v-if="playlist && playlist.error" :message="playlist.message" :error="playlist.error" />
<div v-if="playlist" v-show="!playlist.error">
<h1 class="text-center">
{{ playlist.name }}
</h1>
<div class="grid grid-cols-2">
<div>
<b
><router-link class="uk-text-justify" :to="playlist.uploaderUrl || '/'">
<img :src="playlist.uploaderAvatar" loading="lazy" class="rounded-full" />
{{ playlist.uploader }}</router-link
></b
>
</div>
<div>
<div class="right-2vw absolute">
<b>{{ playlist.videos }} {{ $t("video.videos") }}</b>
<br />
<a :href="getRssUrl"><font-awesome-icon icon="rss"></font-awesome-icon></a>
</div>
</div>
</div>
<hr />
<div class="video-grid">
<div v-for="video in playlist.relatedStreams" :key="video.url">
<VideoItem :video="video" height="94" width="168" />
</div>
</div>
</div>
</template>
<script>
import ErrorHandler from "@/components/ErrorHandler.vue";
import VideoItem from "@/components/VideoItem.vue";
export default {
components: {
ErrorHandler,
VideoItem,
},
data() {
return {
playlist: null,
};
},
computed: {
getRssUrl: _this => {
return _this.apiUrl() + "/rss/playlists/" + _this.$route.query.list;
},
},
mounted() {
this.getPlaylistData();
},
activated() {
window.addEventListener("scroll", this.handleScroll);
},
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchPlaylist() {
return await await this.fetchJson(this.apiUrl() + "/playlists/" + this.$route.query.list);
},
async getPlaylistData() {
this.fetchPlaylist()
.then(data => (this.playlist = data))
.then(() => (document.title = this.playlist.name + " - Piped"));
},
handleScroll() {
if (this.loading || !this.playlist || !this.playlist.nextpage) return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
this.loading = true;
this.fetchJson(this.apiUrl() + "/nextpage/playlists/" + this.$route.query.list, {
nextpage: this.playlist.nextpage,
}).then(json => {
this.playlist.relatedStreams.concat(json.relatedStreams);
this.playlist.nextpage = json.nextpage;
this.loading = false;
json.relatedStreams.map(stream => this.playlist.relatedStreams.push(stream));
});
}
},
},
};
</script>