Add router caching.

This commit is contained in:
FireMasterK 2021-07-07 02:42:51 +05:30
parent 9345e1a917
commit c03a9bf2d6
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
6 changed files with 36 additions and 16 deletions

View file

@ -5,7 +5,11 @@
:class="{ 'uk-light': darkMode }"
>
<Navigation />
<router-view />
<router-view v-slot="{ Component }">
<keep-alive>
<component :key="$route.fullPath" :is="Component" />
</keep-alive>
</router-view>
<div style="text-align: center">
<a aria-label="GitHub" href="https://github.com/TeamPiped/Piped">

View file

@ -32,9 +32,11 @@ export default {
},
mounted() {
this.getChannelData();
},
activated() {
window.addEventListener("scroll", this.handleScroll);
},
unmounted() {
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {

View file

@ -29,6 +29,11 @@ export default {
selectedAutoPlay: Boolean,
selectedAutoLoop: Boolean,
},
data() {
return {
player: null,
};
},
computed: {
shouldAutoPlay: _this => {
return _this.getPreferenceBoolean("playerAutoPlay", true);
@ -196,7 +201,7 @@ export default {
});
},
},
mounted() {
activated() {
import("hotkeys-js")
.then(mod => mod.default)
.then(hotkeys => {
@ -239,11 +244,15 @@ export default {
});
});
},
beforeUnmount() {
deactivated() {
if (this.ui) {
this.ui.destroy();
this.ui = undefined;
this.player = undefined;
}
if (this.player) {
this.player.destroy();
this.player = undefined;
this.ui = undefined;
}
if (this.hotkeys) this.hotkeys.unbind();
},

View file

@ -46,9 +46,11 @@ export default {
},
mounted() {
this.getPlaylistData();
},
activated() {
window.addEventListener("scroll", this.handleScroll);
},
unmounted() {
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
computed: {

View file

@ -86,9 +86,11 @@ export default {
},
mounted() {
this.updateResults();
},
activated() {
window.addEventListener("scroll", this.handleScroll);
},
unmounted() {
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
watch: {

View file

@ -134,21 +134,24 @@ export default {
};
},
mounted() {
this.selectedAutoPlay = this.getPreferenceBoolean("autoplay", true);
this.getVideoData();
this.getVideoData().then(() => {
console.log(this.video.title);
this.$refs.videoPlayer.loadVideo();
});
this.getSponsors();
this.getComments();
},
activated() {
this.selectedAutoPlay = this.getPreferenceBoolean("autoplay", true);
if (this.video.duration) this.$refs.videoPlayer.loadVideo();
window.addEventListener("scroll", this.handleScroll);
},
unmounted() {
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
watch: {
"$route.query.v": function(v) {
if (v) {
this.getVideoData();
this.getSponsors();
this.getComments();
window.scrollTo(0, 0);
}
},
@ -175,7 +178,7 @@ export default {
this.setPreference("autoplay", this.selectedAutoPlay);
},
async getVideoData() {
this.fetchVideo()
await this.fetchVideo()
.then(data => {
this.video = data;
})
@ -189,8 +192,6 @@ export default {
.replaceAll("https://www.youtube.com", "")
.replaceAll("\n", "<br>"),
);
this.$refs.videoPlayer.loadVideo();
}
});
},