Skip to content

Commit

Permalink
Remove duplicate checks for whether history entries exist
Browse files Browse the repository at this point in the history
Co-authored-by: PikachuEXE <pikachuexe@gmail.com>
  • Loading branch information
absidue and PikachuEXE committed Sep 12, 2023
1 parent 7a7cc28 commit 59d025f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export default defineComponent({
return this.$store.getters.getHistoryCacheById[this.id]
},

historyEntryExists: function () {
return typeof this.historyEntry !== 'undefined'
},

listType: function () {
return this.$store.getters.getListType
},
Expand Down Expand Up @@ -441,7 +445,7 @@ export default defineComponent({
this.channelName = this.data.author ?? null
this.channelId = this.data.authorId ?? null

if (this.data.isRSS && typeof this.historyEntry !== 'undefined') {
if (this.data.isRSS && typeof this.historyEntryExists) {
this.duration = formatDurationAsTimestamp(this.historyEntry.lengthSeconds)
} else {
this.duration = formatDurationAsTimestamp(this.data.lengthSeconds)
Expand Down Expand Up @@ -528,10 +532,11 @@ export default defineComponent({
},

checkIfWatched: function () {
const historyEntry = this.historyEntry

if (typeof historyEntry !== 'undefined') {
if (this.historyEntryExists) {
this.watched = true

const historyEntry = this.historyEntry

if (this.saveWatchedProgress) {
// For UX consistency, no progress reading if writing disabled
this.watchProgress = historyEntry.watchProgress
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export default defineComponent({
historyEntry: function () {
return this.$store.getters.getHistoryCacheById[this.videoId]
},
historyEntryExists: function () {
return typeof this.historyEntry !== 'undefined'
},
rememberHistory: function () {
return this.$store.getters.getRememberHistory
},
Expand Down Expand Up @@ -1040,8 +1043,6 @@ export default defineComponent({
},

checkIfWatched: function () {
const historyEntry = this.historyEntry

if (!this.isLive) {
if (this.timestamp) {
if (this.timestamp < 0) {
Expand All @@ -1051,7 +1052,7 @@ export default defineComponent({
} else {
this.$refs.videoPlayer.player.currentTime(this.timestamp)
}
} else if (this.saveWatchedProgress && typeof historyEntry !== 'undefined') {
} else if (this.saveWatchedProgress && this.historyEntryExists) {
// For UX consistency, no progress reading if writing disabled
const watchProgress = this.historyEntry.watchProgress

Expand All @@ -1064,7 +1065,7 @@ export default defineComponent({
if (this.rememberHistory) {
if (this.timestamp) {
this.addToHistory(this.timestamp)
} else if (typeof historyEntry !== 'undefined') {
} else if (this.historyEntryExists) {
this.addToHistory(this.historyEntry.watchProgress)
} else {
this.addToHistory(0)
Expand Down

0 comments on commit 59d025f

Please sign in to comment.