From 722fd343fa7dc88269f34a65b49f7da715e17608 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 2 Jan 2023 06:47:20 +0530 Subject: [PATCH] Paginate the watch history page --- src/routes/WatchHistory.vue | 22 ++++++++++++++++------ src/store/watched-videos-db.js | 9 --------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/routes/WatchHistory.vue b/src/routes/WatchHistory.vue index c85e83c..53e5e29 100644 --- a/src/routes/WatchHistory.vue +++ b/src/routes/WatchHistory.vue @@ -20,6 +20,7 @@ + @@ -27,10 +28,12 @@ import _chunk from 'lodash-es/chunk' import { LibPiped } from '@/tools/libpiped' -import { deleteWatchedVideos, getUnfinishedVideos, getWatchedVideos } from '@/store/watched-videos-db' +import { deleteWatchedVideos, PMDB } from '@/store/watched-videos-db' import VideoItem from '@/components/Video/VideoItem' import ExpandableDate from '@/components/ExpandableDate' +const PAGE_SIZE = 50 + export default { components: { ExpandableDate, @@ -39,6 +42,8 @@ export default { data: () => ({ loaded: false, data: null, + currentPage: 1, + pageCount: 0, unfinishedVideosSwitch: false }), @@ -53,12 +58,13 @@ export default { return LibPiped.timeFormat(t) }, - async loadData (onlyUnfinished = false) { - if (!onlyUnfinished) { - this.data = await getWatchedVideos() + async loadData () { + if (!this.unfinishedVideosSwitch) { + this.data = await PMDB.watchedVideos.orderBy('timestamp').reverse().offset((this.currentPage - 1) * PAGE_SIZE).limit(PAGE_SIZE).toArray() } else { - this.data = await getUnfinishedVideos() + this.data = await PMDB.watchedVideos.where('progressPcnt').below(99.9).reverse().offset((this.currentPage - 1) * PAGE_SIZE).limit(PAGE_SIZE).sortBy('timestamp') } + this.pageCount = Math.ceil((await PMDB.watchedVideos.count()) / PAGE_SIZE) this.loaded = true }, @@ -70,7 +76,11 @@ export default { watch: { unfinishedVideosSwitch () { - this.loadData(this.unfinishedVideosSwitch) + this.loadData() + }, + + currentPage () { + this.loadData() } }, diff --git a/src/store/watched-videos-db.js b/src/store/watched-videos-db.js index 708ed22..7362970 100644 --- a/src/store/watched-videos-db.js +++ b/src/store/watched-videos-db.js @@ -28,15 +28,6 @@ export async function findLastWatch (videoId) { return v[0] } -export function getWatchedVideos () { - return PMDB.watchedVideos.orderBy('timestamp').reverse().toArray() -} - -export function getUnfinishedVideos () { - // Shaka never fires the last event, thus the last percent turns out to be around 99.95 or 99.98 - return PMDB.watchedVideos.where('progressPcnt').below(99.9).reverse().sortBy('timestamp') -} - export function deleteWatchedVideos () { return PMDB.watchedVideos.clear() }