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

Add setting to auto load comment section #3352

Merged
13 changes: 11 additions & 2 deletions src/renderer/components/player-settings/player-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineComponent({
],
screenshotFolderPlaceholder: '',
screenshotFilenameExample: '',
screenshotDefaultPattern: '%Y%M%D-%H%N%S'
screenshotDefaultPattern: '%Y%M%D-%H%N%S',
}
},
computed: {
Expand Down Expand Up @@ -195,7 +195,15 @@ export default defineComponent({

screenshotFilenamePattern: function() {
return this.$store.getters.getScreenshotFilenamePattern
}
},

commentAutoLoadEnabled: function () {
return this.$store.getters.getCommentAutoLoadEnabled
},

hideComments: function () {
return this.$store.getters.getHideComments
},
},
watch: {
screenshotFolder: function() {
Expand Down Expand Up @@ -295,6 +303,7 @@ export default defineComponent({
'updateScreenshotFolderPath',
'updateScreenshotFilenamePattern',
'parseScreenshotCustomFileName',
'updateCommentAutoLoadEnabled',
])
}
})
9 changes: 9 additions & 0 deletions src/renderer/components/player-settings/player-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,16 @@
:disabled="true"
/>
</ft-flex-box>
<br>
</div>
<ft-flex-box>
<ft-toggle-switch
:label="$t('Settings.Player Settings.Comment Auto Load.Comment Auto Load')"
:default-value="commentAutoLoadEnabled"
:disabled="hideComments"
@change="updateCommentAutoLoadEnabled"
/>
</ft-flex-box>
</ft-settings-section>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ export default defineComponent({
channelThumbnail: {
type: String,
required: true
}
},
videoPlayerReady: {
type: Boolean,
required: true
},
},
data: function () {
return {
isLoading: false,
showComments: false,
nextPageToken: null,
commentData: [],
sortNewest: false
sortNewest: false,
}
},
computed: {
Expand All @@ -54,6 +58,10 @@ export default defineComponent({
return this.$store.getters.getHideCommentLikes
},

commentAutoLoadEnabled: function () {
return this.$store.getters.getCommentAutoLoadEnabled
},

sortNames: function () {
return [
this.$t('Comments.Top comments'),
Expand All @@ -70,7 +78,41 @@ export default defineComponent({

currentSortValue: function () {
return (this.sortNewest) ? 'newest' : 'top'
}
},

observeVisibilityOptions: function() {
if (!this.commentAutoLoadEnabled) { return false }
if (!this.videoPlayerReady) { return false }

return {
callback: (isVisible, _entry) => {
// This is also fired when **hidden**
// No point doing anything if not visible
if (!isVisible) { return }
// It's possible the comments are being loaded/already loaded
if (this.canPerformInitialCommentLoading) {
this.getCommentData()
}
if (this.canPerformMoreCommentLoading) {
this.getMoreComments()
}
absidue marked this conversation as resolved.
Show resolved Hide resolved
},
intersection: {
// Only when it intersects with N% above bottom
rootMargin: '0% 0% 0% 0%',
},
// Callback responsible for loading multiple comment pages
once: false,
}
},

canPerformInitialCommentLoading: function() {
return this.commentData.length === 0 && !this.isLoading && !this.showComments
},

canPerformMoreCommentLoading: function() {
return this.commentData.length > 0 && !this.isLoading && this.showComments && this.nextPageToken
},
},

methods: {
Expand Down Expand Up @@ -242,6 +284,6 @@ export default defineComponent({
})
this.isLoading = false
})
}
},
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="card"
>
<h4
v-if="commentData.length === 0 && !isLoading"
v-if="canPerformInitialCommentLoading"
class="getCommentsTitle"
role="button"
tabindex="0"
Expand Down Expand Up @@ -238,7 +238,7 @@
</h3>
</div>
<h4
v-if="commentData.length > 0 && !isLoading && showComments && nextPageToken"
v-if="canPerformMoreCommentLoading"
class="getMoreComments"
role="button"
tabindex="0"
Expand All @@ -251,6 +251,13 @@
<ft-loader
v-if="isLoading"
/>
<div
v-observe-visibility="observeVisibilityOptions"
>
<!--
Dummy element to be observed by Intersection Observer
-->
</div>
</ft-card>
</template>

Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ const state = {
fetchSubscriptionsAutomatically: true,
settingsPassword: '',
allowDashAv1Formats: false,
commentAutoLoadEnabled: false,
}

const stateWithSideEffects = {
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default defineComponent({
isLoading: true,
firstLoad: true,
useTheatreMode: false,
videoPlayerReady: false,
showDashPlayer: true,
showLegacyPlayer: false,
showYouTubeNoCookieEmbed: false,
Expand Down Expand Up @@ -98,7 +99,7 @@ export default defineComponent({
timestamp: null,
playNextTimeout: null,
playNextCountDownIntervalId: null,
infoAreaSticky: true
infoAreaSticky: true,
}
},
computed: {
Expand Down Expand Up @@ -182,7 +183,7 @@ export default defineComponent({
},
allowDashAv1Formats: function () {
return this.$store.getters.getAllowDashAv1Formats
}
},
},
watch: {
$route() {
Expand Down Expand Up @@ -928,6 +929,11 @@ export default defineComponent({
this.updateLastViewedPlaylist(payload)
},

handleVideoReady: function () {
this.videoPlayerReady = true
absidue marked this conversation as resolved.
Show resolved Hide resolved
this.checkIfWatched()
},

checkIfWatched: function () {
const historyIndex = this.historyCache.findIndex((video) => {
return video.videoId === this.videoId
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/views/Watch/Watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:chapters="videoChapters"
class="videoPlayer"
:class="{ theatrePlayer: useTheatreMode }"
@ready="checkIfWatched"
@ready="handleVideoReady"
@ended="handleVideoEnded"
@error="handleVideoError"
@store-caption-list="captionHybridList = $event"
Expand Down Expand Up @@ -144,6 +144,7 @@
:class="{ theatreWatchVideo: useTheatreMode }"
:channel-thumbnail="channelThumbnail"
:channel-name="channelName"
:video-player-ready="videoPlayerReady"
@timestamp-event="changeTimestamp"
/>
</div>
Expand Down
2 changes: 2 additions & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ Settings:
Error:
Forbidden Characters: Forbidden Characters
Empty File Name: Empty File Name
Comment Auto Load:
Comment Auto Load: Comment Auto Load
External Player Settings:
External Player Settings: External Player Settings
External Player: External Player
Expand Down