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

91 lines
2.8 KiB
Vue
Raw Normal View History

<template>
2022-07-21 01:50:10 +05:30
<h1 v-t="'titles.feed'" class="font-bold text-center my-4" />
<button class="btn mr-2" @click="exportHandler">
2022-01-12 17:29:50 +05:30
<router-link to="/subscriptions">Subscriptions</router-link>
2021-09-04 20:32:59 +05:30
</button>
2021-09-04 20:32:59 +05:30
<span>
2021-12-28 04:03:55 +05:30
<a :href="getRssUrl">
2022-01-12 17:29:50 +05:30
<font-awesome-icon icon="rss" />
2021-12-28 04:03:55 +05:30
</a>
2021-09-04 20:32:59 +05:30
</span>
2021-12-27 20:16:29 +05:30
<span class="md:float-right">
2022-05-20 02:47:58 +05:30
<SortingSelector by-key="uploaded" @apply="order => videos.sort(order)" />
2021-09-04 20:32:59 +05:30
</span>
<hr />
2021-12-27 20:16:22 +05:30
<div class="video-grid">
2022-11-01 17:42:54 +05:30
<VideoItem :is-feed="true" v-for="video in videos" :key="video.url" :item="video" />
</div>
</template>
<script>
2022-04-08 21:16:49 +05:30
import VideoItem from "./VideoItem.vue";
2022-05-20 02:47:58 +05:30
import SortingSelector from "./SortingSelector.vue";
export default {
components: {
VideoItem,
2022-05-20 02:47:58 +05:30
SortingSelector,
},
data() {
return {
currentVideoCount: 0,
videoStep: 100,
videosStore: [],
videos: [],
};
},
computed: {
getRssUrl(_this) {
if (_this.authenticated) return _this.authApiUrl() + "/feed/rss?authToken=" + _this.getAuthToken();
else return _this.authApiUrl() + "/feed/unauthenticated/rss?channels=" + _this.getUnauthenticatedChannels();
},
},
mounted() {
this.fetchFeed().then(videos => {
this.videosStore = videos;
this.loadMoreVideos();
this.updateWatched(this.videos);
});
},
activated() {
2021-08-26 01:25:30 +05:30
document.title = this.$t("titles.feed") + " - Piped";
if (this.videos.length > 0) this.updateWatched(this.videos);
window.addEventListener("scroll", this.handleScroll);
},
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
unmounted() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchFeed() {
if (this.authenticated) {
return await this.fetchJson(this.authApiUrl() + "/feed", {
authToken: this.getAuthToken(),
});
} else {
return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", {
channels: this.getUnauthenticatedChannels(),
});
}
},
loadMoreVideos() {
this.currentVideoCount = Math.min(this.currentVideoCount + this.videoStep, this.videosStore.length);
if (this.videos.length != this.videosStore.length)
this.videos = this.videosStore.slice(0, this.currentVideoCount);
},
handleScroll() {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
this.loadMoreVideos();
}
},
},
};
</script>