2021-08-22 15:57:09 +05:30
|
|
|
<template>
|
2022-01-31 05:18:27 +05:30
|
|
|
<h1 class="font-bold text-center" v-t="'titles.history'" />
|
2021-08-22 15:57:09 +05:30
|
|
|
|
2022-01-12 17:29:50 +05:30
|
|
|
<div class="flex">
|
|
|
|
<div>
|
|
|
|
<button class="btn" v-t="'actions.clear_history'" @click="clearHistory" />
|
|
|
|
</div>
|
2021-11-01 00:06:21 +05:30
|
|
|
|
2022-01-12 17:29:50 +05:30
|
|
|
<div class="right-1">
|
|
|
|
<Sorting by-key="watchedAt" @apply="order => videos.sort(order)" />
|
|
|
|
</div>
|
2021-09-04 21:09:04 +05:30
|
|
|
</div>
|
2021-08-22 15:57:09 +05:30
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-12-27 20:16:22 +05:30
|
|
|
<div class="video-grid">
|
2021-12-27 20:16:39 +05:30
|
|
|
<VideoItem v-for="video in videos" :key="video.url" :video="video" />
|
2021-08-22 15:57:09 +05:30
|
|
|
</div>
|
2021-09-04 21:09:04 +05:30
|
|
|
|
|
|
|
<br />
|
2021-08-22 15:57:09 +05:30
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import VideoItem from "@/components/VideoItem.vue";
|
2021-12-28 05:04:59 +05:30
|
|
|
import Sorting from "@/components/Sorting.vue";
|
2021-08-22 15:57:09 +05:30
|
|
|
|
|
|
|
export default {
|
2021-10-09 00:22:51 +05:30
|
|
|
components: {
|
|
|
|
VideoItem,
|
2021-12-28 05:04:59 +05:30
|
|
|
Sorting,
|
2021-10-09 00:22:51 +05:30
|
|
|
},
|
2021-08-22 15:57:09 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
videos: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
(async () => {
|
|
|
|
if (window.db) {
|
|
|
|
var tx = window.db.transaction("watch_history", "readonly");
|
|
|
|
var store = tx.objectStore("watch_history");
|
|
|
|
const cursorRequest = store.openCursor();
|
|
|
|
cursorRequest.onsuccess = e => {
|
|
|
|
const cursor = e.target.result;
|
|
|
|
if (cursor) {
|
|
|
|
const video = cursor.value;
|
|
|
|
this.videos.push({
|
|
|
|
url: "/watch?v=" + video.videoId,
|
|
|
|
title: video.title,
|
|
|
|
uploaderName: video.uploaderName,
|
|
|
|
uploaderUrl: video.uploaderUrl,
|
|
|
|
duration: video.duration,
|
|
|
|
thumbnail: video.thumbnail,
|
|
|
|
watchedAt: video.watchedAt,
|
|
|
|
});
|
|
|
|
this.videos.sort((a, b) => b.watchedAt - a.watchedAt); // TODO: Optimize
|
|
|
|
if (this.videos.length < 1000) cursor.continue();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
document.title = "Watch History - Piped";
|
|
|
|
},
|
|
|
|
methods: {
|
2021-11-01 00:06:21 +05:30
|
|
|
clearHistory() {
|
|
|
|
if (window.db) {
|
|
|
|
var tx = window.db.transaction("watch_history", "readwrite");
|
|
|
|
var store = tx.objectStore("watch_history");
|
|
|
|
store.clear();
|
|
|
|
}
|
|
|
|
this.videos = [];
|
|
|
|
},
|
2021-08-22 15:57:09 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|