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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/FeedPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<LoadingIndicatorPage :show-content="videosStore != null" class="video-grid">
<template v-for="video in videos" :key="video.url">
<VideoItem v-if="shouldShowVideo(video)" :is-feed="true" :item="video" />
<VideoItem v-if="shouldShowVideo(video)" :is-feed="true" :item="video" @update:watched="onUpdateWatched" />
</template>
</LoadingIndicatorPage>
</template>
Expand Down Expand Up @@ -100,6 +100,15 @@ export default {
this.loadMoreVideos();
}
},
onUpdateWatched(urls = null) {
if (urls === null) {
if (this.videos.length > 0) this.updateWatched(this.videos);
return;
}

const subset = this.videos.filter(({ url }) => urls.includes(url));
if (subset.length > 0) this.updateWatched(subset);
},
shouldShowVideo(video) {
switch (this.selectedFilter.toLowerCase()) {
case "shorts":
Expand Down
2 changes: 1 addition & 1 deletion src/components/PreferencesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
@change="onChange($event)"
/>
</label>
<label v-if="watchHistory" class="pref" for="chkHideWatched">
<label class="pref" for="chkHideWatched">
FireMasterK marked this conversation as resolved.
Show resolved Hide resolved
<strong v-t="'actions.hide_watched'" />
<input id="chkHideWatched" v-model="hideWatched" class="checkbox" type="checkbox" @change="onChange($event)" />
</label>
Expand Down
55 changes: 55 additions & 0 deletions src/components/VideoItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@
>
<font-awesome-icon icon="circle-minus" />
</button>
<button
v-if="
isFeed &&
(this.getPreferenceBoolean('watchHistory', false) ||
this.getPreferenceBoolean('hideWatched', false))
"
@click="toggleWatched(item.url.substr(-11))"
ref="watchButton"
>
<font-awesome-icon icon="eye-slash" v-if="item.watched" :title="$t('actions.mark_as_unwatched')" />
<font-awesome-icon icon="eye" v-else :title="$t('actions.mark_as_watched')" />
</button>
<PlaylistAddModal v-if="showModal" :video-id="item.url.substr(-11)" @close="showModal = !showModal" />
</div>
</div>
Expand Down Expand Up @@ -152,6 +164,7 @@ export default {
playlistId: { type: String, default: null },
admin: { type: Boolean, default: false },
},
emits: ["update:watched"],
data() {
return {
showModal: false,
Expand Down Expand Up @@ -194,6 +207,48 @@ export default {
}
};
},
toggleWatched(videoId) {
if (window.db) {
// Should match WatchVideo.vue
var tx = window.db.transaction("watch_history", "readwrite");
var store = tx.objectStore("watch_history");
var instance = this;

if (this.item.watched) {
let request = store.delete(videoId);
request.onsuccess = function () {
instance.$emit("update:watched", [instance.item.url]);
};
return;
}
Comment on lines +217 to +223
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we delete the item, then updateWatched won't really update the watched property if someone marks a video as unwatched. So, the video will still show up as watched until they reload the page.


var request = store.get(videoId);
request.onsuccess = function (event) {
var video = event.target.result;
if (video) {
video.watchedAt = Date.now();
} else {
// Should match WatchVideo.vue
video = {
videoId: videoId,
title: instance.item.title,
duration: instance.item.duration,
thumbnail: instance.item.thumbnailUrl,
uploaderUrl: instance.item.uploaderUrl,
uploaderName: instance.item.uploader,
watchedAt: Date.now(),
};
}
// Set time to end for shouldShowVideo
video.currentTime = instance.item.duration;
// Save
store.put(video);
// Disappear if hideWatched is on
instance.$emit("update:watched", [instance.item.url]);
instance.shouldShowVideo();
};
}
},
},
components: { PlaylistAddModal },
};
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
"show_chapters": "Chapters",
"store_search_history": "Store Search history",
"hide_watched": "Hide watched videos in the feed",
"mark_as_watched": "Mark as Watched",
"mark_as_unwatched": "Mark as Unwatched",
"documentation": "Documentation",
"status_page": "Status",
"source_code": "Source code",
Expand Down
2 changes: 2 additions & 0 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 @@ -26,6 +27,7 @@ import { faGithub, faBitcoin, faYoutube } from "@fortawesome/free-brands-svg-ico
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
library.add(
faEye,
faEyeSlash,
faGithub,
faBitcoin,
faThumbtack,
Expand Down