2021-07-17 04:26:41 +05:30
|
|
|
<template>
|
2022-07-21 01:50:10 +05:30
|
|
|
<h1 v-t="'titles.feed'" class="font-bold text-center my-4" />
|
2021-07-17 04:26:41 +05:30
|
|
|
|
2022-08-01 19:46:06 +05:30
|
|
|
<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-07-17 04:26:41 +05:30
|
|
|
|
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>
|
|
|
|
|
2023-01-27 21:37:02 +05:30
|
|
|
<label for="filters" class="ml-10 mr-2">
|
|
|
|
<strong v-text="`${$t('actions.filter')}:`" />
|
|
|
|
</label>
|
|
|
|
<select id="filters" v-model="selectedFilter" default="all" class="select w-auto" @change="onFilterChange()">
|
|
|
|
<option v-for="filter in availableFilters" :key="filter" :value="filter" v-t="`video.${filter}`" />
|
|
|
|
</select>
|
|
|
|
|
2023-05-07 23:26:56 +05:30
|
|
|
<label for="group-selector" class="ml-10 mr-2">
|
|
|
|
<strong v-text="`${$t('titles.channel_groups')}:`" />
|
|
|
|
</label>
|
|
|
|
<select id="group-selector" v-model="selectedGroupName" default="" class="select w-auto">
|
|
|
|
<option value="" v-t="`video.all`" />
|
|
|
|
<option
|
|
|
|
v-for="group in channelGroups"
|
|
|
|
:key="group.groupName"
|
|
|
|
:value="group.groupName"
|
|
|
|
v-text="group.groupName"
|
|
|
|
/>
|
|
|
|
</select>
|
|
|
|
|
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>
|
2021-07-20 01:14:55 +05:30
|
|
|
|
2021-07-17 04:26:41 +05:30
|
|
|
<hr />
|
|
|
|
|
2023-03-13 19:09:07 +05:30
|
|
|
<LoadingIndicatorPage :show-content="videosStore != null" class="video-grid">
|
2023-05-07 23:26:56 +05:30
|
|
|
<template v-for="video in filteredVideos" :key="video.url">
|
2023-01-27 21:37:02 +05:30
|
|
|
<VideoItem v-if="shouldShowVideo(video)" :is-feed="true" :item="video" />
|
|
|
|
</template>
|
2023-03-13 19:09:07 +05:30
|
|
|
</LoadingIndicatorPage>
|
2021-07-17 04:26:41 +05:30
|
|
|
</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";
|
2023-03-13 19:09:07 +05:30
|
|
|
import LoadingIndicatorPage from "./LoadingIndicatorPage.vue";
|
2021-07-21 18:02:17 +05:30
|
|
|
|
2021-07-17 04:26:41 +05:30
|
|
|
export default {
|
2021-10-09 00:22:51 +05:30
|
|
|
components: {
|
|
|
|
VideoItem,
|
2022-05-20 02:47:58 +05:30
|
|
|
SortingSelector,
|
2023-03-13 19:09:07 +05:30
|
|
|
LoadingIndicatorPage,
|
2021-10-09 00:22:51 +05:30
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
data() {
|
|
|
|
return {
|
2021-09-12 01:01:01 +05:30
|
|
|
currentVideoCount: 0,
|
|
|
|
videoStep: 100,
|
2023-03-13 19:09:07 +05:30
|
|
|
videosStore: null,
|
2021-07-17 04:26:41 +05:30
|
|
|
videos: [],
|
2023-01-27 21:37:02 +05:30
|
|
|
availableFilters: ["all", "shorts", "videos"],
|
|
|
|
selectedFilter: "all",
|
2023-05-07 23:26:56 +05:30
|
|
|
selectedGroupName: "",
|
|
|
|
channelGroups: [],
|
2021-07-17 04:26:41 +05:30
|
|
|
};
|
|
|
|
},
|
2021-10-09 00:22:51 +05:30
|
|
|
computed: {
|
|
|
|
getRssUrl(_this) {
|
2022-08-01 19:46:06 +05:30
|
|
|
if (_this.authenticated) return _this.authApiUrl() + "/feed/rss?authToken=" + _this.getAuthToken();
|
|
|
|
else return _this.authApiUrl() + "/feed/unauthenticated/rss?channels=" + _this.getUnauthenticatedChannels();
|
2021-10-09 00:22:51 +05:30
|
|
|
},
|
2023-05-07 23:26:56 +05:30
|
|
|
filteredVideos(_this) {
|
|
|
|
const selectedGroup = _this.channelGroups.filter(group => group.groupName == _this.selectedGroupName);
|
|
|
|
return _this.selectedGroupName == ""
|
|
|
|
? _this.videos
|
|
|
|
: _this.videos.filter(video => selectedGroup[0].channels.includes(video.uploaderUrl.substr(-11)));
|
|
|
|
},
|
2021-10-09 00:22:51 +05:30
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
mounted() {
|
2022-08-01 19:46:06 +05:30
|
|
|
this.fetchFeed().then(videos => {
|
|
|
|
this.videosStore = videos;
|
|
|
|
this.loadMoreVideos();
|
|
|
|
this.updateWatched(this.videos);
|
|
|
|
});
|
2023-01-27 21:37:02 +05:30
|
|
|
|
2023-01-28 01:42:03 +05:30
|
|
|
this.selectedFilter = this.getPreferenceString("feedFilter") ?? "all";
|
2023-05-07 23:26:56 +05:30
|
|
|
|
|
|
|
if (!window.db) return;
|
|
|
|
|
|
|
|
const cursor = this.getChannelGroupsCursor();
|
|
|
|
cursor.onsuccess = e => {
|
|
|
|
const cursor = e.target.result;
|
|
|
|
if (cursor) {
|
|
|
|
const group = cursor.value;
|
2023-05-08 17:43:32 +05:30
|
|
|
this.channelGroups.push({
|
2023-05-07 23:26:56 +05:30
|
|
|
groupName: group.groupName,
|
|
|
|
channels: JSON.parse(group.channels),
|
|
|
|
});
|
2023-05-08 17:43:32 +05:30
|
|
|
cursor.continue();
|
2023-05-07 23:26:56 +05:30
|
|
|
}
|
|
|
|
};
|
2021-07-17 04:26:41 +05:30
|
|
|
},
|
2021-07-21 16:29:53 +05:30
|
|
|
activated() {
|
2021-08-26 01:25:30 +05:30
|
|
|
document.title = this.$t("titles.feed") + " - Piped";
|
2021-08-22 15:57:09 +05:30
|
|
|
if (this.videos.length > 0) this.updateWatched(this.videos);
|
2021-09-12 01:01:01 +05:30
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
|
|
|
deactivated() {
|
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
2021-07-21 16:29:53 +05:30
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
methods: {
|
|
|
|
async fetchFeed() {
|
2022-08-01 19:46:06 +05:30
|
|
|
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(),
|
|
|
|
});
|
|
|
|
}
|
2021-07-17 04:26:41 +05:30
|
|
|
},
|
2021-09-12 01:01:01 +05:30
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
2023-01-27 21:37:02 +05:30
|
|
|
shouldShowVideo(video) {
|
2023-01-27 23:35:02 +05:30
|
|
|
switch (this.selectedFilter.toLowerCase()) {
|
|
|
|
case "shorts":
|
|
|
|
return video.isShort;
|
2023-01-27 21:37:02 +05:30
|
|
|
case "videos":
|
|
|
|
return !video.isShort;
|
|
|
|
default:
|
2023-01-27 23:35:02 +05:30
|
|
|
return true;
|
2023-01-27 21:37:02 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
onFilterChange() {
|
|
|
|
this.setPreference("feedFilter", this.selectedFilter);
|
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|