mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
Merge pull request #1651 from Bnyro/channeltabs
Support for channel tabs
This commit is contained in:
commit
f5d4da7c2b
4 changed files with 154 additions and 47 deletions
|
@ -35,13 +35,25 @@
|
||||||
<font-awesome-icon icon="rss" />
|
<font-awesome-icon icon="rss" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<div class="flex mt-4 mb-2">
|
||||||
|
<button
|
||||||
|
v-for="(tab, index) in tabs"
|
||||||
|
:key="tab.name"
|
||||||
|
class="btn mr-2"
|
||||||
|
@click="loadTab(index)"
|
||||||
|
:class="{ active: selectedTab == index }"
|
||||||
|
>
|
||||||
|
<span v-text="tab.translatedName"></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<div class="video-grid">
|
<div class="video-grid">
|
||||||
<VideoItem
|
<ContentItem
|
||||||
v-for="video in channel.relatedStreams"
|
v-for="item in contentItems"
|
||||||
:key="video.url"
|
:key="item.url"
|
||||||
:video="video"
|
:content-item="item"
|
||||||
height="94"
|
height="94"
|
||||||
width="168"
|
width="168"
|
||||||
hide-channel
|
hide-channel
|
||||||
|
@ -52,17 +64,21 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ErrorHandler from "./ErrorHandler.vue";
|
import ErrorHandler from "./ErrorHandler.vue";
|
||||||
import VideoItem from "./VideoItem.vue";
|
import ContentItem from "./ContentItem.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
ErrorHandler,
|
ErrorHandler,
|
||||||
VideoItem,
|
ContentItem,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
channel: null,
|
channel: null,
|
||||||
subscribed: false,
|
subscribed: false,
|
||||||
|
tabs: [],
|
||||||
|
selectedTab: 0,
|
||||||
|
contentItems: [],
|
||||||
|
tabNextPage: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -111,8 +127,17 @@ export default {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!this.channel.error) {
|
if (!this.channel.error) {
|
||||||
document.title = this.channel.name + " - Piped";
|
document.title = this.channel.name + " - Piped";
|
||||||
|
this.contentItems = this.channel.relatedStreams;
|
||||||
this.fetchSubscribedStatus();
|
this.fetchSubscribedStatus();
|
||||||
this.updateWatched(this.channel.relatedStreams);
|
this.updateWatched(this.channel.relatedStreams);
|
||||||
|
this.tabs.push({
|
||||||
|
translatedName: this.$t("video.videos"),
|
||||||
|
});
|
||||||
|
for (let i = 0; i < this.channel.tabs.length; i++) {
|
||||||
|
let tab = this.channel.tabs[i];
|
||||||
|
tab.translatedName = this.getTranslatedTabName(tab.name);
|
||||||
|
this.tabs.push(tab);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -120,16 +145,33 @@ export default {
|
||||||
if (this.loading || !this.channel || !this.channel.nextpage) return;
|
if (this.loading || !this.channel || !this.channel.nextpage) return;
|
||||||
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
|
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, {
|
if (this.selectedTab == 0) {
|
||||||
nextpage: this.channel.nextpage,
|
this.fetchChannelNextPage();
|
||||||
}).then(json => {
|
} else {
|
||||||
this.channel.nextpage = json.nextpage;
|
this.fetchChannelTabNextPage();
|
||||||
this.loading = false;
|
}
|
||||||
this.updateWatched(json.relatedStreams);
|
|
||||||
json.relatedStreams.map(stream => this.channel.relatedStreams.push(stream));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fetchChannelNextPage() {
|
||||||
|
this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, {
|
||||||
|
nextpage: this.channel.nextpage,
|
||||||
|
}).then(json => {
|
||||||
|
this.channel.nextpage = json.nextpage;
|
||||||
|
this.loading = false;
|
||||||
|
this.updateWatched(json.relatedStreams);
|
||||||
|
json.relatedStreams.map(stream => this.contentItems.push(stream));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fetchChannelTabNextPage() {
|
||||||
|
this.fetchJson(this.apiUrl() + "/channels/tabs", {
|
||||||
|
data: this.tabs[this.selectedTab].data,
|
||||||
|
nextpage: this.tabNextPage,
|
||||||
|
}).then(json => {
|
||||||
|
this.tabNextPage = json.nextpage;
|
||||||
|
this.loading = false;
|
||||||
|
json.content.map(item => this.contentItems.push(item));
|
||||||
|
});
|
||||||
|
},
|
||||||
subscribeHandler() {
|
subscribeHandler() {
|
||||||
if (this.authenticated) {
|
if (this.authenticated) {
|
||||||
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
||||||
|
@ -147,6 +189,46 @@ export default {
|
||||||
}
|
}
|
||||||
this.subscribed = !this.subscribed;
|
this.subscribed = !this.subscribed;
|
||||||
},
|
},
|
||||||
|
getTranslatedTabName(tabName) {
|
||||||
|
let translatedTabName = tabName;
|
||||||
|
switch (tabName) {
|
||||||
|
case "Livestreams":
|
||||||
|
translatedTabName = this.$t("titles.livestreams");
|
||||||
|
break;
|
||||||
|
case "Playlists":
|
||||||
|
translatedTabName = this.$t("titles.playlists");
|
||||||
|
break;
|
||||||
|
case "Channels":
|
||||||
|
translatedTabName = this.$t("titles.channels");
|
||||||
|
break;
|
||||||
|
case "Shorts":
|
||||||
|
translatedTabName = this.$t("video.shorts");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error(`Tab name "${tabName}" is not translated yet!`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return translatedTabName;
|
||||||
|
},
|
||||||
|
loadTab(index) {
|
||||||
|
this.selectedTab = index;
|
||||||
|
if (index == 0) {
|
||||||
|
this.contentItems = this.channel.relatedStreams;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.fetchJson(this.apiUrl() + "/channels/tabs", {
|
||||||
|
data: this.tabs[index].data,
|
||||||
|
}).then(tab => {
|
||||||
|
this.contentItems = tab.content;
|
||||||
|
this.tabNextPage = tab.nextpage;
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.active {
|
||||||
|
border: 0.1rem outset red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
52
src/components/ContentItem.vue
Normal file
52
src/components/ContentItem.vue
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<template>
|
||||||
|
<VideoItem v-if="shouldUseVideoItem(contentItem)" :video="contentItem" height="94" width="168" />
|
||||||
|
<div v-else>
|
||||||
|
<router-link :to="contentItem.url">
|
||||||
|
<div class="relative">
|
||||||
|
<img class="w-full" :src="contentItem.thumbnail" loading="lazy" />
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
<span v-text="contentItem.name" />
|
||||||
|
<font-awesome-icon class="ml-1.5" v-if="contentItem.verified" icon="check" />
|
||||||
|
</p>
|
||||||
|
</router-link>
|
||||||
|
<p v-if="contentItem.description" v-text="contentItem.description" />
|
||||||
|
<router-link v-if="contentItem.uploaderUrl" class="link" :to="contentItem.uploaderUrl">
|
||||||
|
<p>
|
||||||
|
<span v-text="contentItem.uploader" />
|
||||||
|
<font-awesome-icon class="ml-1.5" v-if="contentItem.uploaderVerified" icon="check" />
|
||||||
|
</p>
|
||||||
|
</router-link>
|
||||||
|
|
||||||
|
<a v-if="contentItem.uploaderName" class="link" v-text="contentItem.uploaderName" />
|
||||||
|
<template v-if="contentItem.videos >= 0">
|
||||||
|
<br v-if="contentItem.uploaderName" />
|
||||||
|
<strong v-text="`${contentItem.videos} ${$t('video.videos')}`" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import VideoItem from "./VideoItem.vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
VideoItem,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
contentItem: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
shouldUseVideoItem(item) {
|
||||||
|
return item.title;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -20,43 +20,17 @@
|
||||||
|
|
||||||
<div v-if="results" class="video-grid">
|
<div v-if="results" class="video-grid">
|
||||||
<template v-for="result in results.items" :key="result.url">
|
<template v-for="result in results.items" :key="result.url">
|
||||||
<VideoItem v-if="shouldUseVideoItem(result)" :video="result" height="94" width="168" />
|
<ContentItem :content-item="result" />
|
||||||
<div v-if="!shouldUseVideoItem(result)">
|
|
||||||
<router-link :to="result.url">
|
|
||||||
<div class="relative">
|
|
||||||
<img class="w-full" :src="result.thumbnail" loading="lazy" />
|
|
||||||
</div>
|
|
||||||
<p>
|
|
||||||
<span v-text="result.name" />
|
|
||||||
<font-awesome-icon class="ml-1.5" v-if="result.verified" icon="check" />
|
|
||||||
</p>
|
|
||||||
</router-link>
|
|
||||||
<p v-if="result.description" v-text="result.description" />
|
|
||||||
<router-link v-if="result.uploaderUrl" class="link" :to="result.uploaderUrl">
|
|
||||||
<p>
|
|
||||||
<span v-text="result.uploader" />
|
|
||||||
<font-awesome-icon class="ml-1.5" v-if="result.uploaderVerified" icon="check" />
|
|
||||||
</p>
|
|
||||||
</router-link>
|
|
||||||
|
|
||||||
<a v-if="result.uploaderName" class="link" v-text="result.uploaderName" />
|
|
||||||
<template v-if="result.videos >= 0">
|
|
||||||
<br v-if="result.uploaderName" />
|
|
||||||
<strong v-text="`${result.videos} ${$t('video.videos')}`" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<br />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import VideoItem from "./VideoItem.vue";
|
import ContentItem from "./ContentItem.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
VideoItem,
|
ContentItem,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -124,9 +98,6 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
shouldUseVideoItem(item) {
|
|
||||||
return item.title;
|
|
||||||
},
|
|
||||||
handleRedirect() {
|
handleRedirect() {
|
||||||
const query = this.$route.query.search_query;
|
const query = this.$route.query.search_query;
|
||||||
const url =
|
const url =
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
"playlists": "Playlists",
|
"playlists": "Playlists",
|
||||||
"account": "Account",
|
"account": "Account",
|
||||||
"instance": "Instance",
|
"instance": "Instance",
|
||||||
"player": "Player"
|
"player": "Player",
|
||||||
|
"livestreams": "Livestreams",
|
||||||
|
"channels": "Channels"
|
||||||
},
|
},
|
||||||
"player": {
|
"player": {
|
||||||
"watch_on": "Watch on {0}"
|
"watch_on": "Watch on {0}"
|
||||||
|
|
Loading…
Reference in a new issue