diff --git a/src/App.vue b/src/App.vue index 4e74b80b..66a70eb1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -41,6 +41,23 @@ export default { default: break; } + + if (this.getPreferenceBoolean("watchHistory", false)) + if ("indexedDB" in window) { + const request = indexedDB.open("piped-db", 1); + request.onupgradeneeded = function() { + const db = request.result; + console.log("Upgrading object store."); + if (!db.objectStoreNames.contains("watch_history")) { + const store = db.createObjectStore("watch_history", { keyPath: "videoId" }); + store.createIndex("video_id_idx", "videoId", { unique: true }); + store.createIndex("id_idx", "id", { unique: true, autoIncrement: true }); + } + }; + request.onsuccess = e => { + window.db = e.target.result; + }; + } else console.log("This browser doesn't support IndexedDB"); }, }; diff --git a/src/components/Channel.vue b/src/components/Channel.vue index fce23adf..978a7d9f 100644 --- a/src/components/Channel.vue +++ b/src/components/Channel.vue @@ -47,6 +47,7 @@ export default { activated() { if (this.channel && !this.channel.error) document.title = this.channel.name + " - Piped"; window.addEventListener("scroll", this.handleScroll); + if (this.channel && !this.channel.error) this.updateWatched(this.channel.relatedStreams); }, deactivated() { window.removeEventListener("scroll", this.handleScroll); @@ -78,6 +79,7 @@ export default { if (!this.channel.error) { document.title = this.channel.name + " - Piped"; if (this.authenticated) this.fetchSubscribedStatus(); + this.updateWatched(this.channel.relatedStreams); } }); }, @@ -88,9 +90,9 @@ export default { this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, { nextpage: this.channel.nextpage, }).then(json => { - this.channel.relatedStreams.concat(json.relatedStreams); this.channel.nextpage = json.nextpage; this.loading = false; + this.updateWatched(json.relatedStreams); json.relatedStreams.map(stream => this.channel.relatedStreams.push(stream)); }); } diff --git a/src/components/FeedPage.vue b/src/components/FeedPage.vue index 90d505be..aa1b8544 100644 --- a/src/components/FeedPage.vue +++ b/src/components/FeedPage.vue @@ -44,10 +44,14 @@ export default { }; }, mounted() { - this.fetchFeed().then(videos => (this.videos = videos)); + this.fetchFeed().then(videos => { + this.videos = videos; + this.updateWatched(this.videos); + }); }, activated() { document.title = "Feed - Piped"; + if (this.videos.length > 0) this.updateWatched(this.videos); }, methods: { async fetchFeed() { diff --git a/src/components/HistoryPage.vue b/src/components/HistoryPage.vue new file mode 100644 index 00000000..0a87a796 --- /dev/null +++ b/src/components/HistoryPage.vue @@ -0,0 +1,88 @@ + + + diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index 60f967cf..66862fb6 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -50,7 +50,6 @@ export default { }, methods: { login() { - console.log("authToken" + this.hashCode(this.apiUrl())); this.fetchJson(this.apiUrl() + "/login", null, { method: "POST", body: JSON.stringify({ diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue index 6ff4ca61..7e0a7edb 100644 --- a/src/components/Navigation.vue +++ b/src/components/Navigation.vue @@ -6,7 +6,13 @@ >
logoiped
@@ -31,6 +37,9 @@
  • Register
  • +
  • + History +
  • Feed
  • @@ -73,6 +82,9 @@ export default { shouldShowLogin(_this) { return _this.getAuthToken() == null; }, + shouldShowHistory(_this) { + return _this.getPreferenceBoolean("watchHistory", false); + }, }, methods: { onKeyUp(e) { diff --git a/src/components/Preferences.vue b/src/components/Preferences.vue index 65dae628..7ce37f81 100644 --- a/src/components/Preferences.vue +++ b/src/components/Preferences.vue @@ -1,8 +1,8 @@