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

Lazy load playlist components to improve performance #2993

Merged
merged 1 commit into from
Dec 26, 2022
Merged
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
55 changes: 55 additions & 0 deletions src/renderer/components/ft-list-video-lazy/ft-list-video-lazy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Vue from 'vue'
import FtListVideo from '../ft-list-video/ft-list-video.vue'

export default Vue.extend({
name: 'FtListVideoLazy',
components: {
'ft-list-video': FtListVideo
},
props: {
data: {
type: Object,
required: true
},
playlistId: {
type: String,
default: null
},
playlistIndex: {
type: Number,
default: null
},
playlistReverse: {
type: Boolean,
default: false
},
playlistShuffle: {
type: Boolean,
default: false
},
playlistLoop: {
type: Boolean,
default: false
},
forceListType: {
type: String,
default: null
},
appearance: {
type: String,
required: true
}
},
data: function () {
return {
visible: false
}
},
methods: {
onVisibilityChanged: function (visible) {
if (visible) {
this.visible = visible
}
}
}
})
23 changes: 23 additions & 0 deletions src/renderer/components/ft-list-video-lazy/ft-list-video-lazy.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div
v-observe-visibility="{
callback: onVisibilityChanged,
once: true,
}"
>
<ft-list-video
v-if="visible"
:data="data"
:playlist-id="playlistId"
:playlist-index="playlistIndex"
:playlist-reverse="playlistReverse"
:playlist-shuffle="playlistShuffle"
:playlist-loop="playlistLoop"
:force-list-type="forceListType"
:appearance="appearance"
@pause-player="$emit('pause-player')"
/>
</div>
</template>

<script src="./ft-list-video-lazy.js" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue from 'vue'
import { mapActions, mapMutations } from 'vuex'
import FtLoader from '../ft-loader/ft-loader.vue'
import FtCard from '../ft-card/ft-card.vue'
import FtListVideo from '../ft-list-video/ft-list-video.vue'
import FtListVideoLazy from '../ft-list-video-lazy/ft-list-video-lazy.vue'
import { copyToClipboard, showToast } from '../../helpers/utils'
import { getLocalPlaylist, parseLocalPlaylistVideo } from '../../helpers/api/local'

Expand All @@ -11,7 +11,7 @@ export default Vue.extend({
components: {
'ft-loader': FtLoader,
'ft-card': FtCard,
'ft-list-video': FtListVideo
'ft-list-video-lazy': FtListVideoLazy
},
props: {
playlistId: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
{{ index + 1 }}
</p>
</div>
<ft-list-video
<ft-list-video-lazy
:data="item"
:playlist-id="playlistId"
:playlist-index="reversePlaylist ? playlistItems.length - index - 1 : index"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Vue from 'vue'
import { mapActions } from 'vuex'
import FtCard from '../ft-card/ft-card.vue'
import FtListVideo from '../ft-list-video/ft-list-video.vue'
import FtListVideoLazy from '../ft-list-video-lazy/ft-list-video-lazy.vue'
import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.vue'

export default Vue.extend({
name: 'WatchVideoRecommendations',
components: {
'ft-card': FtCard,
'ft-list-video': FtListVideo,
'ft-list-video-lazy': FtListVideoLazy,
'ft-toggle-switch': FtToggleSwitch
},
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@change="updatePlayNextVideo"
/>
</div>
<ft-list-video
<ft-list-video-lazy
v-for="(video, index) in data"
:key="index"
:data="video"
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mapActions, mapMutations } from 'vuex'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtCard from '../../components/ft-card/ft-card.vue'
import PlaylistInfo from '../../components/playlist-info/playlist-info.vue'
import FtListVideo from '../../components/ft-list-video/ft-list-video.vue'
import FtListVideoLazy from '../../components/ft-list-video-lazy/ft-list-video-lazy.vue'
import FtFlexBox from '../../components/ft-flex-box/ft-flex-box.vue'
import FtButton from '../../components/ft-button/ft-button.vue'
import i18n from '../../i18n/index'
Expand All @@ -16,7 +16,7 @@ export default Vue.extend({
'ft-loader': FtLoader,
'ft-card': FtCard,
'playlist-info': PlaylistInfo,
'ft-list-video': FtListVideo,
'ft-list-video-lazy': FtListVideoLazy,
'ft-flex-box': FtFlexBox,
'ft-button': FtButton
},
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/Playlist/Playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
>
{{ index + 1 }}
</p>
<ft-list-video
<ft-list-video-lazy
:data="item"
:playlist-id="playlistId"
:playlist-index="index"
Expand Down