2021-07-16 22:56:41 +00:00
|
|
|
<template>
|
2022-07-20 20:20:10 +00:00
|
|
|
<h1 v-t="'titles.feed'" class="font-bold text-center my-4" />
|
2021-07-16 22:56:41 +00:00
|
|
|
|
2022-08-01 14:16:06 +00:00
|
|
|
<button class="btn mr-2" @click="exportHandler">
|
2022-01-12 11:59:50 +00:00
|
|
|
<router-link to="/subscriptions">Subscriptions</router-link>
|
2021-09-04 15:02:59 +00:00
|
|
|
</button>
|
2021-07-16 22:56:41 +00:00
|
|
|
|
2021-09-04 15:02:59 +00:00
|
|
|
<span>
|
2021-12-27 22:33:55 +00:00
|
|
|
<a :href="getRssUrl">
|
2022-01-12 11:59:50 +00:00
|
|
|
<font-awesome-icon icon="rss" />
|
2021-12-27 22:33:55 +00:00
|
|
|
</a>
|
2021-09-04 15:02:59 +00:00
|
|
|
</span>
|
|
|
|
|
2023-01-27 16:07:02 +00:00
|
|
|
<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 17:56:56 +00:00
|
|
|
<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 14:46:29 +00:00
|
|
|
<span class="md:float-right">
|
2022-05-19 21:17:58 +00:00
|
|
|
<SortingSelector by-key="uploaded" @apply="order => videos.sort(order)" />
|
2021-09-04 15:02:59 +00:00
|
|
|
</span>
|
2021-07-19 19:44:55 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
<hr />
|
|
|
|
|
2023-03-13 13:39:07 +00:00
|
|
|
<LoadingIndicatorPage :show-content="videosStore != null" class="video-grid">
|
2023-05-07 17:56:56 +00:00
|
|
|
<template v-for="video in filteredVideos" :key="video.url">
|
2023-01-27 16:07:02 +00:00
|
|
|
<VideoItem v-if="shouldShowVideo(video)" :is-feed="true" :item="video" />
|
|
|
|
</template>
|
2023-03-13 13:39:07 +00:00
|
|
|
</LoadingIndicatorPage>
|
2021-07-16 22:56:41 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-08 15:46:49 +00:00
|
|
|
import VideoItem from "./VideoItem.vue";
|
2022-05-19 21:17:58 +00:00
|
|
|
import SortingSelector from "./SortingSelector.vue";
|
2023-03-13 13:39:07 +00:00
|
|
|
import LoadingIndicatorPage from "./LoadingIndicatorPage.vue";
|
2021-07-21 12:32:17 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
export default {
|
2021-10-08 18:52:51 +00:00
|
|
|
components: {
|
|
|
|
VideoItem,
|
2022-05-19 21:17:58 +00:00
|
|
|
SortingSelector,
|
2023-03-13 13:39:07 +00:00
|
|
|
LoadingIndicatorPage,
|
2021-10-08 18:52:51 +00:00
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2021-09-11 19:31:01 +00:00
|
|
|
currentVideoCount: 0,
|
|
|
|
videoStep: 100,
|
2023-03-13 13:39:07 +00:00
|
|
|
videosStore: null,
|
2021-07-16 22:56:41 +00:00
|
|
|
videos: [],
|
2023-01-27 16:07:02 +00:00
|
|
|
availableFilters: ["all", "shorts", "videos"],
|
|
|
|
selectedFilter: "all",
|
2023-05-07 17:56:56 +00:00
|
|
|
selectedGroupName: "",
|
|
|
|
channelGroups: [],
|
2021-07-16 22:56:41 +00:00
|
|
|
};
|
|
|
|
},
|
2021-10-08 18:52:51 +00:00
|
|
|
computed: {
|
|
|
|
getRssUrl(_this) {
|
2022-08-01 14:16:06 +00:00
|
|
|
if (_this.authenticated) return _this.authApiUrl() + "/feed/rss?authToken=" + _this.getAuthToken();
|
|
|
|
else return _this.authApiUrl() + "/feed/unauthenticated/rss?channels=" + _this.getUnauthenticatedChannels();
|
2021-10-08 18:52:51 +00:00
|
|
|
},
|
2023-05-07 17:56:56 +00:00
|
|
|
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-08 18:52:51 +00:00
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
mounted() {
|
2022-08-01 14:16:06 +00:00
|
|
|
this.fetchFeed().then(videos => {
|
|
|
|
this.videosStore = videos;
|
|
|
|
this.loadMoreVideos();
|
|
|
|
this.updateWatched(this.videos);
|
|
|
|
});
|
2023-01-27 16:07:02 +00:00
|
|
|
|
2023-01-27 20:12:03 +00:00
|
|
|
this.selectedFilter = this.getPreferenceString("feedFilter") ?? "all";
|
2023-05-07 17:56:56 +00:00
|
|
|
|
|
|
|
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 12:13:32 +00:00
|
|
|
this.channelGroups.push({
|
2023-05-07 17:56:56 +00:00
|
|
|
groupName: group.groupName,
|
|
|
|
channels: JSON.parse(group.channels),
|
|
|
|
});
|
2023-05-08 12:13:32 +00:00
|
|
|
cursor.continue();
|
2023-05-07 17:56:56 +00:00
|
|
|
}
|
|
|
|
};
|
2021-07-16 22:56:41 +00:00
|
|
|
},
|
2021-07-21 10:59:53 +00:00
|
|
|
activated() {
|
2021-08-25 19:55:30 +00:00
|
|
|
document.title = this.$t("titles.feed") + " - Piped";
|
2021-08-22 10:27:09 +00:00
|
|
|
if (this.videos.length > 0) this.updateWatched(this.videos);
|
2021-09-11 19:31:01 +00:00
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
|
|
|
deactivated() {
|
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
2021-07-21 10:59:53 +00:00
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
methods: {
|
|
|
|
async fetchFeed() {
|
2022-08-01 14:16:06 +00:00
|
|
|
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-16 22:56:41 +00:00
|
|
|
},
|
2021-09-11 19:31:01 +00:00
|
|
|
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 16:07:02 +00:00
|
|
|
shouldShowVideo(video) {
|
2023-01-27 18:05:02 +00:00
|
|
|
switch (this.selectedFilter.toLowerCase()) {
|
|
|
|
case "shorts":
|
|
|
|
return video.isShort;
|
2023-01-27 16:07:02 +00:00
|
|
|
case "videos":
|
|
|
|
return !video.isShort;
|
|
|
|
default:
|
2023-01-27 18:05:02 +00:00
|
|
|
return true;
|
2023-01-27 16:07:02 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onFilterChange() {
|
|
|
|
this.setPreference("feedFilter", this.selectedFilter);
|
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|