2020-11-27 06:46:36 +00:00
|
|
|
<template>
|
2021-06-06 18:47:43 +00:00
|
|
|
<ErrorHandler v-if="channel && channel.error" :message="channel.message" :error="channel.error" />
|
|
|
|
|
|
|
|
<div v-if="channel" v-show="!channel.error">
|
2021-09-05 20:53:59 +00:00
|
|
|
<h1 class="uk-text-center">
|
2021-10-08 18:52:51 +00:00
|
|
|
<img height="48" width="48" class="uk-border-circle" :src="channel.avatarUrl" />{{ channel.name }}
|
2021-09-05 20:53:59 +00:00
|
|
|
</h1>
|
2021-10-08 18:52:51 +00:00
|
|
|
<img v-if="channel.bannerUrl" :src="channel.bannerUrl" style="width: 100%" loading="lazy" />
|
|
|
|
<!-- eslint-disable-next-line vue/no-v-html -->
|
2021-07-24 15:17:12 +00:00
|
|
|
<p style="white-space: pre-wrap"><span v-html="purifyHTML(urlify(channel.description))"></span></p>
|
2020-11-27 06:46:36 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
<button
|
|
|
|
v-if="authenticated"
|
|
|
|
class="uk-button uk-button-small"
|
|
|
|
style="background: #222"
|
|
|
|
type="button"
|
2021-10-08 18:52:51 +00:00
|
|
|
@click="subscribeHandler"
|
2021-07-16 22:56:41 +00:00
|
|
|
>
|
2021-09-05 13:08:26 +00:00
|
|
|
{{ subscribed ? $t("actions.unsubscribe") : $t("actions.subscribe") }}
|
2021-07-16 22:56:41 +00:00
|
|
|
</button>
|
|
|
|
|
2020-11-27 06:46:36 +00:00
|
|
|
<hr />
|
|
|
|
|
2021-10-31 17:44:36 +00:00
|
|
|
<div class="uk-grid uk-grid-xl">
|
2020-11-27 06:46:36 +00:00
|
|
|
<div
|
2021-10-08 18:52:51 +00:00
|
|
|
v-for="video in channel.relatedStreams"
|
|
|
|
:key="video.url"
|
2020-11-27 06:46:36 +00:00
|
|
|
class="uk-width-1-2 uk-width-1-3@m uk-width-1-4@l uk-width-1-5@xl"
|
|
|
|
>
|
2021-10-08 18:52:51 +00:00
|
|
|
<VideoItem :video="video" height="94" width="168" hide-channel />
|
2020-11-27 06:46:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-06-06 18:47:43 +00:00
|
|
|
import ErrorHandler from "@/components/ErrorHandler.vue";
|
2021-06-16 19:14:46 +00:00
|
|
|
import VideoItem from "@/components/VideoItem.vue";
|
2020-11-27 06:46:36 +00:00
|
|
|
|
|
|
|
export default {
|
2021-10-08 18:52:51 +00:00
|
|
|
components: {
|
|
|
|
ErrorHandler,
|
|
|
|
VideoItem,
|
|
|
|
},
|
2020-11-27 06:46:36 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2021-04-07 11:45:40 +00:00
|
|
|
channel: null,
|
2021-07-16 22:56:41 +00:00
|
|
|
subscribed: false,
|
2020-11-27 06:46:36 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getChannelData();
|
2021-07-07 14:18:09 +00:00
|
|
|
},
|
|
|
|
activated() {
|
2021-07-21 10:59:53 +00:00
|
|
|
if (this.channel && !this.channel.error) document.title = this.channel.name + " - Piped";
|
2020-11-27 06:46:36 +00:00
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
2021-08-22 10:27:09 +00:00
|
|
|
if (this.channel && !this.channel.error) this.updateWatched(this.channel.relatedStreams);
|
2020-11-27 06:46:36 +00:00
|
|
|
},
|
2021-07-07 14:18:09 +00:00
|
|
|
deactivated() {
|
2020-11-27 06:46:36 +00:00
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
2021-09-05 20:53:59 +00:00
|
|
|
unmounted() {
|
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
2020-11-27 06:46:36 +00:00
|
|
|
methods: {
|
2021-07-16 22:56:41 +00:00
|
|
|
async fetchSubscribedStatus() {
|
|
|
|
this.fetchJson(
|
|
|
|
this.apiUrl() + "/subscribed",
|
|
|
|
{
|
|
|
|
channelId: this.channel.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
).then(json => {
|
|
|
|
this.subscribed = json.subscribed;
|
|
|
|
});
|
|
|
|
},
|
2020-11-27 06:46:36 +00:00
|
|
|
async fetchChannel() {
|
2021-07-04 18:26:02 +00:00
|
|
|
const url = this.apiUrl() + "/" + this.$route.params.path + "/" + this.$route.params.channelId;
|
2021-05-28 18:40:54 +00:00
|
|
|
return await this.fetchJson(url);
|
2020-11-27 06:46:36 +00:00
|
|
|
},
|
|
|
|
async getChannelData() {
|
|
|
|
this.fetchChannel()
|
|
|
|
.then(data => (this.channel = data))
|
2021-06-06 18:47:43 +00:00
|
|
|
.then(() => {
|
2021-07-16 22:56:41 +00:00
|
|
|
if (!this.channel.error) {
|
|
|
|
document.title = this.channel.name + " - Piped";
|
|
|
|
if (this.authenticated) this.fetchSubscribedStatus();
|
2021-08-22 10:27:09 +00:00
|
|
|
this.updateWatched(this.channel.relatedStreams);
|
2021-07-16 22:56:41 +00:00
|
|
|
}
|
2021-06-06 18:47:43 +00:00
|
|
|
});
|
2020-11-27 06:46:36 +00:00
|
|
|
},
|
|
|
|
handleScroll() {
|
2021-06-05 19:35:14 +00:00
|
|
|
if (this.loading || !this.channel || !this.channel.nextpage) return;
|
2021-04-07 11:45:40 +00:00
|
|
|
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
|
2020-11-27 06:46:36 +00:00
|
|
|
this.loading = true;
|
2021-07-04 18:26:02 +00:00
|
|
|
this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, {
|
2021-06-15 11:37:35 +00:00
|
|
|
nextpage: this.channel.nextpage,
|
|
|
|
}).then(json => {
|
2021-02-24 09:35:41 +00:00
|
|
|
this.channel.nextpage = json.nextpage;
|
|
|
|
this.loading = false;
|
2021-08-22 10:27:09 +00:00
|
|
|
this.updateWatched(json.relatedStreams);
|
2021-04-07 11:45:40 +00:00
|
|
|
json.relatedStreams.map(stream => this.channel.relatedStreams.push(stream));
|
2021-02-24 09:35:41 +00:00
|
|
|
});
|
2020-11-27 06:46:36 +00:00
|
|
|
}
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
subscribeHandler() {
|
|
|
|
this.fetchJson(this.apiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: this.channel.id,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.subscribed = !this.subscribed;
|
|
|
|
},
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
2020-11-27 06:46:36 +00:00
|
|
|
};
|
|
|
|
</script>
|