24
24
25
25
<hr />
26
26
27
- <LoadingIndicatorPage :show-content =" videosStore != null" class =" video-grid" >
27
+ <LoadingIndicatorPage :show-content =" videos != null" class =" video-grid" >
28
28
<template v-for =" video in videos " :key =" video .url " >
29
29
<VideoItem v-if =" shouldShowVideo(video)" :is-feed =" true" :item =" video" />
30
30
</template >
@@ -44,12 +44,11 @@ export default {
44
44
},
45
45
data () {
46
46
return {
47
- currentVideoCount: 0 ,
48
- videoStep: 100 ,
49
- videosStore: null ,
50
- videos: [],
47
+ videos: null ,
48
+ videosCount: 0 ,
51
49
availableFilters: [" all" , " shorts" , " videos" ],
52
50
selectedFilter: " all" ,
51
+ loading: false ,
53
52
};
54
53
},
55
54
computed: {
@@ -60,16 +59,16 @@ export default {
60
59
},
61
60
mounted () {
62
61
this .fetchFeed ().then (videos => {
63
- this .videosStore = videos;
64
- this .loadMoreVideos () ;
62
+ this .videos = videos;
63
+ this .videosCount = videos . length ;
65
64
this .updateWatched (this .videos );
66
65
});
67
66
68
67
this .selectedFilter = this .getPreferenceString (" feedFilter" ) ?? " all" ;
69
68
},
70
69
activated () {
71
70
document .title = this .$t (" titles.feed" ) + " - Piped" ;
72
- if (this .videos .length > 0 ) this .updateWatched (this .videos );
71
+ if (this .videos ? .length > 0 ) this .updateWatched (this .videos );
73
72
window .addEventListener (" scroll" , this .handleScroll );
74
73
},
75
74
deactivated () {
@@ -90,13 +89,35 @@ export default {
90
89
});
91
90
}
92
91
},
93
- loadMoreVideos () {
94
- this .currentVideoCount = Math .min (this .currentVideoCount + this .videoStep , this .videosStore .length );
95
- if (this .videos .length != this .videosStore .length )
96
- this .videos = this .videosStore .slice (0 , this .currentVideoCount );
92
+ async loadMoreVideos () {
93
+ const start = this .videos [this .videos .length - 1 ].uploaded ;
94
+ if (this .authenticated ) {
95
+ return await this .fetchJson (this .authApiUrl () + " /feed" , {
96
+ authToken: this .getAuthToken (),
97
+ start,
98
+ }).then (videos => {
99
+ this .videos = this .videos .concat (videos);
100
+ this .videosCount = videos .length > 0 ? this .videos .length : - 1 ;
101
+ this .loading = false ;
102
+ });
103
+ } else {
104
+ return await this .fetchJson (this .authApiUrl () + " /feed/unauthenticated" , {
105
+ channels: this .getUnauthenticatedChannels (),
106
+ start,
107
+ }).then (videos => {
108
+ this .videos = this .videos .concat (videos);
109
+ this .videosCount = videos .length > 0 ? this .videos .length : - 1 ;
110
+ this .loading = false ;
111
+ });
112
+ }
97
113
},
98
114
handleScroll () {
99
115
if (window .innerHeight + window .scrollY >= document .body .offsetHeight - window .innerHeight ) {
116
+ if (this .loading ) return ;
117
+ if (this .videos == null ) return ;
118
+ if (this .videosCount % 100 != 0 ) return ;
119
+
120
+ this .loading = true ;
100
121
this .loadMoreVideos ();
101
122
}
102
123
},
0 commit comments