2021-08-22 10:27:09 +00:00
|
|
|
<template>
|
2022-01-30 23:48:27 +00:00
|
|
|
<h1 class="font-bold text-center" v-t="'titles.history'" />
|
2021-08-22 10:27:09 +00:00
|
|
|
|
2022-01-12 11:59:50 +00:00
|
|
|
<div class="flex">
|
|
|
|
<div>
|
|
|
|
<button class="btn" v-t="'actions.clear_history'" @click="clearHistory" />
|
|
|
|
</div>
|
2021-10-31 18:36:21 +00:00
|
|
|
|
2022-01-12 11:59:50 +00:00
|
|
|
<div class="right-1">
|
2022-05-19 21:17:58 +00:00
|
|
|
<SortingSelector by-key="watchedAt" @apply="order => videos.sort(order)" />
|
2022-01-12 11:59:50 +00:00
|
|
|
</div>
|
2021-09-04 15:39:04 +00:00
|
|
|
</div>
|
2021-08-22 10:27:09 +00:00
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-12-27 14:46:22 +00:00
|
|
|
<div class="video-grid">
|
2021-12-27 14:46:39 +00:00
|
|
|
<VideoItem v-for="video in videos" :key="video.url" :video="video" />
|
2021-08-22 10:27:09 +00:00
|
|
|
</div>
|
2021-09-04 15:39:04 +00:00
|
|
|
|
|
|
|
<br />
|
2021-08-22 10:27:09 +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";
|
2021-08-22 10:27:09 +00:00
|
|
|
|
|
|
|
export default {
|
2021-10-08 18:52:51 +00:00
|
|
|
components: {
|
|
|
|
VideoItem,
|
2022-05-19 21:17:58 +00:00
|
|
|
SortingSelector,
|
2021-10-08 18:52:51 +00:00
|
|
|
},
|
2021-08-22 10:27:09 +00:00
|
|
|
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-10-31 18:36:21 +00:00
|
|
|
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 10:27:09 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|