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

Update watch view playlist component to auto scroll to current video #3399

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent } from 'vue'
import { defineComponent, nextTick } from 'vue'
import { mapMutations } from 'vuex'
import FtLoader from '../ft-loader/ft-loader.vue'
import FtCard from '../ft-card/ft-card.vue'
Expand All @@ -12,7 +12,7 @@ export default defineComponent({
components: {
'ft-loader': FtLoader,
'ft-card': FtCard,
'ft-list-video-lazy': FtListVideoLazy
'ft-list-video-lazy': FtListVideoLazy,
},
props: {
playlistId: {
Expand All @@ -22,7 +22,11 @@ export default defineComponent({
videoId: {
type: String,
required: true
}
},
watchViewLoading: {
type: Boolean,
required: true
},
},
data: function () {
return {
Expand Down Expand Up @@ -79,6 +83,26 @@ export default defineComponent({
this.shufflePlaylistItems()
}
}
},
watchViewLoading: function(newVal, oldVal) {
// This component is loaded/rendered before watch view loaded
if (oldVal && !newVal) {
// If loading true => false
// setTimeout to put this into event queue
// executed after render
// Scroll current item into view after render complete
const container = this.$refs.playlistItems
const currentVideoItem = (this.$refs.currentVideoItem || [])[0]
if (container != null && currentVideoItem != null) {
container.scrollTop = currentVideoItem.offsetTop - container.offsetTop
// Since components are only rendered after scroll,
// the scroll position requires another adjustment
// Timeout value depends on how soon the components finish rendering
nextTick(() => {
container.scrollTop = currentVideoItem.offsetTop - container.offsetTop
})
}
}
}
},
mounted: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@
</p>
<div
v-if="!isLoading"
ref="playlistItems"
class="playlistItems"
>
<div
v-for="(item, index) in playlistItems"
:key="index"
:ref="currentVideoIndex === (index + 1) ? 'currentVideoItem' : null"
class="playlistItem"
>
<div class="videoIndexContainer">
Expand Down
1 change: 1 addition & 0 deletions src/renderer/views/Watch/Watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
v-if="watchingPlaylist"
v-show="!isLoading"
ref="watchVideoPlaylist"
:watch-view-loading="isLoading"
:playlist-id="playlistId"
:video-id="videoId"
class="watchVideoSideBar watchVideoPlaylist"
Expand Down