2021-08-22 10:27:09 +00:00
|
|
|
<template>
|
2021-12-27 14:46:26 +00:00
|
|
|
<h1 class="font-bold text-center">{{ $t("titles.history") }}</h1>
|
2021-08-22 10:27:09 +00:00
|
|
|
|
2021-10-31 18:36:21 +00:00
|
|
|
<div style="text-align: left">
|
2021-12-27 14:46:26 +00:00
|
|
|
<button class="btn" v-t="'actions.clear_history'" @click="clearHistory"></button>
|
2021-10-31 18:36:21 +00:00
|
|
|
</div>
|
|
|
|
|
2021-09-04 15:39:04 +00:00
|
|
|
<div style="text-align: right">
|
2021-09-05 21:31:46 +00:00
|
|
|
<label for="ddlSortBy">{{ $t("actions.sort_by") }}</label>
|
2021-12-27 14:46:29 +00:00
|
|
|
<select id="ddlSortBy" v-model="selectedSort" class="select w-auto" @change="onChange()">
|
2021-10-08 18:52:51 +00:00
|
|
|
<option v-t="'actions.most_recent'" value="descending" />
|
|
|
|
<option v-t="'actions.least_recent'" value="ascending" />
|
|
|
|
<option v-t="'actions.channel_name_asc'" value="channel_ascending" />
|
|
|
|
<option v-t="'actions.channel_name_desc'" value="channel_descending" />
|
2021-09-04 15:39:04 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
2021-08-22 10:27:09 +00:00
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-12-27 14:46:22 +00:00
|
|
|
<div class="video-grid">
|
|
|
|
<div v-for="video in videos" :key="video.url" :style="[{ background: backgroundColor }]">
|
2021-08-22 10:27:09 +00:00
|
|
|
<VideoItem :video="video" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-04 15:39:04 +00:00
|
|
|
|
|
|
|
<br />
|
2021-08-22 10:27:09 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import VideoItem from "@/components/VideoItem.vue";
|
|
|
|
|
|
|
|
export default {
|
2021-10-08 18:52:51 +00:00
|
|
|
components: {
|
|
|
|
VideoItem,
|
|
|
|
},
|
2021-08-22 10:27:09 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
videos: [],
|
|
|
|
selectedSort: "descending",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
onChange() {
|
|
|
|
switch (this.selectedSort) {
|
|
|
|
case "ascending":
|
|
|
|
this.videos.sort((a, b) => a.watchedAt - b.watchedAt);
|
|
|
|
break;
|
|
|
|
case "descending":
|
|
|
|
this.videos.sort((a, b) => b.watchedAt - a.watchedAt);
|
|
|
|
break;
|
|
|
|
case "channel_ascending":
|
|
|
|
this.videos.sort((a, b) => a.uploaderName.localeCompare(b.uploaderName));
|
|
|
|
break;
|
|
|
|
case "channel_descending":
|
|
|
|
this.videos.sort((a, b) => b.uploaderName.localeCompare(a.uploaderName));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
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>
|