Deregister scroll listener properly, only fetch more if timeline is visible.

This commit is contained in:
Shpuld Shpuldson 2017-11-02 16:26:17 +02:00
parent 63473964f8
commit 10bc83018c

View file

@ -33,7 +33,7 @@ const Timeline = {
const credentials = store.state.users.currentUser.credentials const credentials = store.state.users.currentUser.credentials
const showImmediately = this.timeline.visibleStatuses.length === 0 const showImmediately = this.timeline.visibleStatuses.length === 0
window.onscroll = this.scrollLoad window.addEventListener('scroll', this.scrollLoad)
timelineFetcher.fetchAndUpdate({ timelineFetcher.fetchAndUpdate({
store, store,
@ -50,6 +50,9 @@ const Timeline = {
this.fetchFollowers() this.fetchFollowers()
} }
}, },
destroyed () {
window.removeEventListener('scroll', this.scrollLoad)
},
methods: { methods: {
showNewStatuses () { showNewStatuses () {
this.$store.commit('showNewStatuses', { timeline: this.timelineName }) this.$store.commit('showNewStatuses', { timeline: this.timelineName })
@ -80,7 +83,10 @@ const Timeline = {
}, },
scrollLoad (e) { scrollLoad (e) {
let height = Math.max(document.body.offsetHeight, document.body.scrollHeight) let height = Math.max(document.body.offsetHeight, document.body.scrollHeight)
if (this.timeline.loading === false && this.$store.state.config.autoLoad && (window.innerHeight + window.pageYOffset) >= (height - 750)) { if (this.timeline.loading === false &&
this.$store.state.config.autoLoad &&
this.$el.offsetHeight > 0 &&
(window.innerHeight + window.pageYOffset) >= (height - 750)) {
this.fetchOlderStatuses() this.fetchOlderStatuses()
} }
} }