Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Mark as Watched button in Feed #1581

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
11 changes: 10 additions & 1 deletion src/components/FeedPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
<hr />

<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>
</template>

Expand Down Expand Up @@ -85,6 +91,9 @@ export default {
this.loadMoreVideos();
}
},
onUpdateWatched() {
if (this.videos.length > 0) this.updateWatched(this.videos);
},
FireMasterK marked this conversation as resolved.
Show resolved Hide resolved
},
};
</script>
28 changes: 22 additions & 6 deletions src/components/VideoItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,16 @@
<font-awesome-icon icon="circle-minus" />
</button>
<button
v-if="isFeed && this.getPreferenceBoolean('hideWatched', false)"
@click="markAsWatched(video.url.substr(-11))"
v-if="
isFeed &&
(this.getPreferenceBoolean('watchHistory', false) ||
this.getPreferenceBoolean('hideWatched', false))
"
@click="toggleWatched(video.url.substr(-11))"
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>
<PlaylistAddModal v-if="showModal" :video-id="video.url.substr(-11)" @close="showModal = !showModal" />
</div>
Expand Down Expand Up @@ -148,6 +153,7 @@ export default {
playlistId: { type: String, default: null },
admin: { type: Boolean, default: false },
},
emits: ["update:watched"],
data() {
return {
showModal: false,
Expand Down Expand Up @@ -190,13 +196,22 @@ export default {
}
};
},
markAsWatched(videoId) {
toggleWatched(videoId) {
if (window.db) {
// Should match WatchVideo.vue
var tx = window.db.transaction("watch_history", "readwrite");
var store = tx.objectStore("watch_history");
var request = store.get(videoId);
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) {
var video = event.target.result;
if (video) {
Expand All @@ -217,7 +232,8 @@ export default {
video.currentTime = instance.video.duration;
// Save
store.put(video);
// Disappear
// Disappear if hideWatched is on
instance.$emit("update:watched");
instance.shouldShowVideo();
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createApp } from "vue";
import { library } from "@fortawesome/fontawesome-svg-core";
import {
faEye,
faEyeSlash,
faThumbtack,
faCheck,
faHeart,
Expand All @@ -25,6 +26,7 @@ import { faGithub, faBitcoin } from "@fortawesome/free-brands-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
library.add(
faEye,
faEyeSlash,
faGithub,
faBitcoin,
faThumbtack,
Expand Down Expand Up @@ -197,9 +199,7 @@ const mixin = {
videos.map(async video => {
var request = store.get(video.url.substr(-11));
request.onsuccess = function (event) {
if (event.target.result) {
video.watched = true;
}
video.watched = Boolean(event.target.result);
};
});
}
Expand Down