1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-15 14:50:28 +05:30
Piped/src/components/Channel.vue

80 lines
2.8 KiB
Vue
Raw Normal View History

2020-11-27 12:16:36 +05:30
<template>
<ErrorHandler v-if="channel && channel.error" :message="channel.message" :error="channel.error" />
<div v-if="channel" v-show="!channel.error">
2021-04-24 00:41:51 +05:30
<h1 class="uk-text-center"><img height="48" width="48" v-bind:src="channel.avatarUrl" />{{ channel.name }}</h1>
<img v-if="channel.bannerUrl" v-bind:src="channel.bannerUrl" style="width: 100%" loading="lazy" />
<p style="white-space: pre-wrap">{{ channel.description }}</p>
2020-11-27 12:16:36 +05:30
<hr />
<div class="uk-grid-xl" uk-grid="parallax: 0">
<div
class="uk-width-1-2 uk-width-1-3@m uk-width-1-4@l uk-width-1-5@xl"
2021-06-17 00:44:46 +05:30
v-bind:key="video.url"
v-for="video in this.channel.relatedStreams"
2020-11-27 12:16:36 +05:30
>
2021-06-17 00:44:46 +05:30
<VideoItem :video="video" height="94" width="168" hideChannel />
2020-11-27 12:16:36 +05:30
</div>
</div>
</div>
</template>
<script>
import Constants from "@/Constants.js";
import ErrorHandler from "@/components/ErrorHandler.vue";
2021-06-17 00:44:46 +05:30
import VideoItem from "@/components/VideoItem.vue";
2020-11-27 12:16:36 +05:30
export default {
data() {
return {
channel: null,
2020-11-27 12:16:36 +05:30
};
},
mounted() {
this.getChannelData();
window.addEventListener("scroll", this.handleScroll);
},
unmounted() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchChannel() {
2021-05-29 00:10:54 +05:30
const url =
Constants.BASE_URL +
(this.$route.params.channelId
? "/channels/" + this.$route.params.channelId
: this.$route.params.channelC
? "/c/" + this.$route.params.channelC
: "/user/" + this.$route.params.channelUser);
return await this.fetchJson(url);
2020-11-27 12:16:36 +05:30
},
async getChannelData() {
this.fetchChannel()
.then(data => (this.channel = data))
.then(() => {
if (!this.channel.error) document.title = this.channel.name + " - Piped";
});
2020-11-27 12:16:36 +05:30
},
handleScroll() {
if (this.loading || !this.channel || !this.channel.nextpage) return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
2020-11-27 12:16:36 +05:30
this.loading = true;
this.fetchJson(Constants.BASE_URL + "/nextpage/channels/" + this.channel.id, {
nextpage: this.channel.nextpage,
}).then(json => {
2021-02-24 15:05:41 +05:30
this.channel.relatedStreams.concat(json.relatedStreams);
this.channel.nextpage = json.nextpage;
this.loading = false;
json.relatedStreams.map(stream => this.channel.relatedStreams.push(stream));
2021-02-24 15:05:41 +05:30
});
2020-11-27 12:16:36 +05:30
}
},
},
components: {
ErrorHandler,
2021-06-17 00:44:46 +05:30
VideoItem,
},
2020-11-27 12:16:36 +05:30
};
</script>