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

118 lines
3.8 KiB
Vue
Raw Normal View History

<template>
<h1 v-t="'titles.feed'" class="uk-text-bold uk-text-center" />
2021-09-04 20:32:59 +05:30
<button
v-if="authenticated"
class="uk-button uk-button-small"
style="background: #222; margin-right: 0.5rem"
type="button"
@click="exportHandler"
2021-09-04 20:32:59 +05:30
>
<router-link to="/subscriptions">
Subscriptions
</router-link>
</button>
2021-09-04 20:32:59 +05:30
<span>
2021-09-04 20:54:36 +05:30
<a :href="getRssUrl"><font-awesome-icon icon="rss" style="padding-top: 0.2rem"></font-awesome-icon></a>
2021-09-04 20:32:59 +05:30
</span>
<span class="uk-align-right@m">
<label for="ddlSortBy">{{ $t("actions.sort_by") }}</label>
<select id="ddlSortBy" v-model="selectedSort" class="uk-select uk-width-auto" @change="onChange()">
<option v-t="'actions.most_recent'" value="descending" />
<option v-t="'actions.least_recent'" value="ascending" />
<option v-t="'actions.channel_name_asc'" value="channel_ascending" />
<option v-t="'actions.channel_name_desc'" value="channel_descending" />
2021-09-04 20:32:59 +05:30
</select>
</span>
<hr />
<div class="uk-grid-xl" uk-grid="parallax: 0">
<div
v-for="video in videos"
:key="video.url"
:style="[{ background: backgroundColor }]"
class="uk-width-1-1 uk-width-1-3@s uk-width-1-4@m uk-width-1-5@l uk-width-1-6@xl"
>
<VideoItem :video="video" />
</div>
</div>
</template>
<script>
import VideoItem from "@/components/VideoItem.vue";
export default {
components: {
VideoItem,
},
data() {
return {
currentVideoCount: 0,
videoStep: 100,
videosStore: [],
videos: [],
2021-07-27 23:34:27 +05:30
selectedSort: "descending",
};
},
computed: {
getRssUrl(_this) {
return _this.apiUrl() + "/feed/rss?authToken=" + _this.getAuthToken();
},
},
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() {
return await this.fetchJson(this.apiUrl() + "/feed", {
authToken: this.getAuthToken(),
});
},
2021-07-27 23:34:27 +05:30
onChange() {
switch (this.selectedSort) {
case "ascending":
this.videos.sort((a, b) => a.uploaded - b.uploaded);
break;
case "descending":
this.videos.sort((a, b) => b.uploaded - a.uploaded);
break;
case "channel_ascending":
this.videos.sort((a, b) => a.uploaderName.localeCompare(b.uploaderName));
break;
case "channel_descending":
this.videos.sort((a, b) => b.uploaderName.localeCompare(a.uploaderName));
break;
}
},
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>