diff --git a/src/components/ChannelPage.vue b/src/components/ChannelPage.vue index d08ce459..b99e844a 100644 --- a/src/components/ChannelPage.vue +++ b/src/components/ChannelPage.vue @@ -35,13 +35,25 @@ +
+ +
+
- import ErrorHandler from "./ErrorHandler.vue"; -import VideoItem from "./VideoItem.vue"; +import ContentItem from "./ContentItem.vue"; export default { components: { ErrorHandler, - VideoItem, + ContentItem, }, data() { return { channel: null, subscribed: false, + tabs: [], + selectedTab: 0, + contentItems: [], + tabNextPage: null, }; }, mounted() { @@ -111,8 +127,17 @@ export default { .then(() => { if (!this.channel.error) { document.title = this.channel.name + " - Piped"; + this.contentItems = this.channel.relatedStreams; this.fetchSubscribedStatus(); 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 (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) { this.loading = true; - 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.channel.relatedStreams.push(stream)); - }); + if (this.selectedTab == 0) { + this.fetchChannelNextPage(); + } else { + this.fetchChannelTabNextPage(); + } } }, + 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() { if (this.authenticated) { this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, { @@ -147,6 +189,46 @@ export default { } 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; + }); + }, }, }; + + diff --git a/src/components/ContentItem.vue b/src/components/ContentItem.vue new file mode 100644 index 00000000..ec3d1608 --- /dev/null +++ b/src/components/ContentItem.vue @@ -0,0 +1,52 @@ + + + diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index 8d3098b8..2325965d 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -20,43 +20,17 @@