Switch to toggle watch.

This commit is contained in:
Chris Hallberg 2022-10-21 16:32:58 -04:00
parent 0674a70624
commit ae460bbcde
3 changed files with 35 additions and 10 deletions

View file

@ -18,7 +18,13 @@
<hr /> <hr />
<div class="video-grid"> <div class="video-grid">
<VideoItem :is-feed="true" v-for="video in videos" :key="video.url" :video="video" /> <VideoItem
:is-feed="true"
v-for="video in videos"
:key="video.url"
:video="video"
@update:watched="onUpdateWatched"
/>
</div> </div>
</template> </template>
@ -85,6 +91,9 @@ export default {
this.loadMoreVideos(); this.loadMoreVideos();
} }
}, },
onUpdateWatched() {
if (this.videos.length > 0) this.updateWatched(this.videos);
},
}, },
}; };
</script> </script>

View file

@ -74,11 +74,16 @@
<font-awesome-icon icon="circle-minus" /> <font-awesome-icon icon="circle-minus" />
</button> </button>
<button <button
v-if="isFeed && this.getPreferenceBoolean('hideWatched', false)" v-if="
@click="markAsWatched(video.url.substr(-11))" isFeed &&
(this.getPreferenceBoolean('watchHistory', false) ||
this.getPreferenceBoolean('hideWatched', false))
"
@click="toggleWatched(video.url.substr(-11))"
ref="watchButton" ref="watchButton"
> >
<font-awesome-icon icon="eye" :title="$t('actions.mark_as_watched')" /> <font-awesome-icon icon="eye-slash" :title="$t('actions.mark_as_unwatched')" v-if="video.watched" />
<font-awesome-icon icon="eye" :title="$t('actions.mark_as_watched')" v-else />
</button> </button>
<PlaylistAddModal v-if="showModal" :video-id="video.url.substr(-11)" @close="showModal = !showModal" /> <PlaylistAddModal v-if="showModal" :video-id="video.url.substr(-11)" @close="showModal = !showModal" />
</div> </div>
@ -148,6 +153,7 @@ export default {
playlistId: { type: String, default: null }, playlistId: { type: String, default: null },
admin: { type: Boolean, default: false }, admin: { type: Boolean, default: false },
}, },
emits: ["update:watched"],
data() { data() {
return { return {
showModal: false, showModal: false,
@ -190,13 +196,22 @@ export default {
} }
}; };
}, },
markAsWatched(videoId) { toggleWatched(videoId) {
if (window.db) { if (window.db) {
// Should match WatchVideo.vue // Should match WatchVideo.vue
var tx = window.db.transaction("watch_history", "readwrite"); var tx = window.db.transaction("watch_history", "readwrite");
var store = tx.objectStore("watch_history"); var store = tx.objectStore("watch_history");
var request = store.get(videoId);
var instance = this; var instance = this;
if (this.video.watched) {
let request = store.delete(videoId);
request.onsuccess = function () {
instance.$emit("update:watched");
};
return;
}
var request = store.get(videoId);
request.onsuccess = function (event) { request.onsuccess = function (event) {
var video = event.target.result; var video = event.target.result;
if (video) { if (video) {
@ -217,7 +232,8 @@ export default {
video.currentTime = instance.video.duration; video.currentTime = instance.video.duration;
// Save // Save
store.put(video); store.put(video);
// Disappear // Disappear if hideWatched is on
instance.$emit("update:watched");
instance.shouldShowVideo(); instance.shouldShowVideo();
}; };
} }

View file

@ -2,6 +2,7 @@ import { createApp } from "vue";
import { library } from "@fortawesome/fontawesome-svg-core"; import { library } from "@fortawesome/fontawesome-svg-core";
import { import {
faEye, faEye,
faEyeSlash,
faThumbtack, faThumbtack,
faCheck, faCheck,
faHeart, faHeart,
@ -25,6 +26,7 @@ import { faGithub, faBitcoin } from "@fortawesome/free-brands-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
library.add( library.add(
faEye, faEye,
faEyeSlash,
faGithub, faGithub,
faBitcoin, faBitcoin,
faThumbtack, faThumbtack,
@ -197,9 +199,7 @@ const mixin = {
videos.map(async video => { videos.map(async video => {
var request = store.get(video.url.substr(-11)); var request = store.get(video.url.substr(-11));
request.onsuccess = function (event) { request.onsuccess = function (event) {
if (event.target.result) { video.watched = Boolean(event.target.result);
video.watched = true;
}
}; };
}); });
} }