logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe
commit: e21f78e519e4d820fa7ffa76d7273489b106761a
parent: eeddceee6baa90c166cfafe2e9759f82d88017b2
Author: lambda <pleromagit@rogerbraun.net>
Date:   Sun, 12 Aug 2018 10:45:36 +0000

Merge branch 'doNotAutoFetchOnUnfocusedTab' into 'develop'

Made it so that unfocused tab doesn't autostream posts when scrolled to the top

See merge request pleroma/pleroma-fe!299

Diffstat:

Msrc/components/timeline/timeline.js15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js @@ -13,7 +13,8 @@ const Timeline = { ], data () { return { - paused: false + paused: false, + unfocused: false } }, computed: { @@ -65,8 +66,15 @@ const Timeline = { this.fetchFollowers() } }, + mounted () { + if (typeof document.hidden !== 'undefined') { + document.addEventListener('visibilitychange', this.handleVisibilityChange, false) + this.unfocused = document.hidden + } + }, destroyed () { window.removeEventListener('scroll', this.scrollLoad) + if (typeof document.hidden !== 'undefined') document.removeEventListener('visibilitychange', this.handleVisibilityChange, false) this.$store.commit('setLoading', { timeline: this.timelineName, value: false }) }, methods: { @@ -113,6 +121,9 @@ const Timeline = { (window.innerHeight + window.pageYOffset) >= (height - 750)) { this.fetchOlderStatuses() } + }, + handleVisibilityChange () { + this.unfocused = document.hidden } }, watch: { @@ -122,7 +133,7 @@ const Timeline = { } if (count > 0) { // only 'stream' them when you're scrolled to the top - if (window.pageYOffset < 15 && !this.paused) { + if (window.pageYOffset < 15 && !this.paused && !this.unfocused) { this.showNewStatuses() } else { this.paused = true