logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe
commit: dcf030470dc42fbd518e3b4600b98cad1e06a84c
parent: e901e064de8f961450129013978ca72666a7e7e8
Author: lambadalambda <gitgud@rogerbraun.net>
Date:   Sat,  3 Jun 2017 12:30:51 -0400

Merge branch 'feature/autoloading-when-scrolled-to-bottom' into 'develop'

Automatic loading/infinite scrolling

See merge request !85

Diffstat:

Msrc/components/settings/settings.js4++++
Msrc/components/settings/settings.vue4++++
Msrc/components/timeline/timeline.js7+++++++
Msrc/main.js1+
Msrc/modules/config.js1+
5 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/components/settings/settings.js b/src/components/settings/settings.js @@ -7,6 +7,7 @@ const settings = { hideAttachmentsLocal: this.$store.state.config.hideAttachments, hideAttachmentsInConvLocal: this.$store.state.config.hideAttachmentsInConv, hideNsfwLocal: this.$store.state.config.hideNsfw, + autoLoadLocal: this.$store.state.config.autoLoad, muteWordsString: this.$store.state.config.muteWords.join('\n') } }, @@ -23,6 +24,9 @@ const settings = { hideNsfwLocal (value) { this.$store.dispatch('setOption', { name: 'hideNsfw', value }) }, + autoLoadLocal (value) { + this.$store.dispatch('setOption', { name: 'autoLoad', value }) + }, muteWordsString (value) { value = filter(value.split('\n'), (word) => trim(word).length > 0) this.$store.dispatch('setOption', { name: 'muteWords', value }) diff --git a/src/components/settings/settings.vue b/src/components/settings/settings.vue @@ -28,6 +28,10 @@ <input type="checkbox" id="hideNsfw" v-model="hideNsfwLocal"> <label for="hideNsfw">Enable clickthrough NSFW attachment hiding</label> </li> + <li> + <input type="checkbox" id="autoLoad" v-model="autoLoadLocal"> + <label for="autoLoad">Enable automatic loading when scrolled to the bottom</label> + </li> </ul> </div> </div> diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js @@ -20,6 +20,8 @@ const Timeline = { const credentials = store.state.users.currentUser.credentials const showImmediately = this.timeline.visibleStatuses.length === 0 + window.onscroll = this.scrollLoad + timelineFetcher.fetchAndUpdate({ store, credentials, @@ -42,6 +44,11 @@ const Timeline = { older: true, showImmediately: true }).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false })) + }, + scrollLoad (e) { + if (this.timeline.loading === false && this.$store.state.config.autoLoad && (window.innerHeight + window.pageYOffset) >= (document.body.scrollHeight - 750)) { + this.fetchOlderStatuses() + } } } } diff --git a/src/main.js b/src/main.js @@ -33,6 +33,7 @@ const persistedStateOptions = { 'config.hideAttachments', 'config.hideAttachmentsInConv', 'config.hideNsfw', + 'config.autoLoad', 'config.muteWords', 'statuses.notifications', 'users.users' diff --git a/src/modules/config.js b/src/modules/config.js @@ -7,6 +7,7 @@ const defaultState = { hideAttachments: false, hideAttachmentsInConv: false, hideNsfw: true, + autoLoad: true, muteWords: [] }