mirror of
https://github.com/TeamPiped/Piped.git
synced 2025-04-26 00:26:36 +00:00
feat: add pagination to history page
Co-authored-by: Bnyro <bnyro@tutanota.com>
This commit is contained in:
parent
8d00447dff
commit
4daa9cfc34
@ -50,6 +50,9 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
currentVideoCount: 0,
|
||||||
|
videoStep: 100,
|
||||||
|
videosStore: [],
|
||||||
videos: [],
|
videos: [],
|
||||||
autoDeleteHistory: false,
|
autoDeleteHistory: false,
|
||||||
autoDeleteDelayHours: "24",
|
autoDeleteDelayHours: "24",
|
||||||
@ -64,33 +67,43 @@ export default {
|
|||||||
var tx = window.db.transaction("watch_history", "readwrite");
|
var tx = window.db.transaction("watch_history", "readwrite");
|
||||||
var store = tx.objectStore("watch_history");
|
var store = tx.objectStore("watch_history");
|
||||||
const cursorRequest = store.index("watchedAt").openCursor(null, "prev");
|
const cursorRequest = store.index("watchedAt").openCursor(null, "prev");
|
||||||
cursorRequest.onsuccess = e => {
|
const cursorPromise = new Promise(resolve => {
|
||||||
const cursor = e.target.result;
|
cursorRequest.onsuccess = e => {
|
||||||
if (cursor) {
|
const cursor = e.target.result;
|
||||||
const video = cursor.value;
|
if (cursor) {
|
||||||
if (this.videos.length < 1000) cursor.continue();
|
const video = cursor.value;
|
||||||
if (!this.shouldRemoveVideo(video)) {
|
if (!this.shouldRemoveVideo(video)) {
|
||||||
this.videos.push({
|
this.videosStore.push({
|
||||||
url: "/watch?v=" + video.videoId,
|
url: "/watch?v=" + video.videoId,
|
||||||
title: video.title,
|
title: video.title,
|
||||||
uploaderName: video.uploaderName,
|
uploaderName: video.uploaderName,
|
||||||
uploaderUrl: video.uploaderUrl,
|
uploaderUrl: video.uploaderUrl,
|
||||||
duration: video.duration,
|
duration: video.duration,
|
||||||
thumbnail: video.thumbnail,
|
thumbnail: video.thumbnail,
|
||||||
watchedAt: video.watchedAt,
|
watchedAt: video.watchedAt,
|
||||||
watched: true,
|
watched: true,
|
||||||
currentTime: video.currentTime,
|
currentTime: video.currentTime,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
store.delete(video.videoId);
|
store.delete(video.videoId);
|
||||||
}
|
}
|
||||||
}
|
if (this.videosStore.length < 1000) cursor.continue();
|
||||||
};
|
else resolve();
|
||||||
|
} else resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
await cursorPromise;
|
||||||
}
|
}
|
||||||
})();
|
})().then(() => {
|
||||||
|
this.loadMoreVideos();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
activated() {
|
activated() {
|
||||||
document.title = "Watch History - Piped";
|
document.title = "Watch History - Piped";
|
||||||
|
window.addEventListener("scroll", this.handleScroll);
|
||||||
|
},
|
||||||
|
deactivated() {
|
||||||
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
clearHistory() {
|
clearHistory() {
|
||||||
@ -127,6 +140,16 @@ export default {
|
|||||||
let maximumTimeDiff = Number(this.autoDeleteDelayHours) * 60 * 60 * 1000;
|
let maximumTimeDiff = Number(this.autoDeleteDelayHours) * 60 * 60 * 1000;
|
||||||
return Date.now() - video.watchedAt > maximumTimeDiff;
|
return Date.now() - video.watchedAt > maximumTimeDiff;
|
||||||
},
|
},
|
||||||
|
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>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user