diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2020-05-31 21:53:56 +0900 |
|---|---|---|
| committer | tamaina <tamaina@hotmail.co.jp> | 2020-05-31 21:53:56 +0900 |
| commit | fb91ab4080ade2234d6ea21cd877d635d226b6c3 (patch) | |
| tree | 0caee66bde5d6565358b190ab57f259c353445c8 /src/client/scripts/paging.ts | |
| parent | Refactor (diff) | |
| parent | fix(client): 全既読系ボタンのAPIの指定が間違っているのを... (diff) | |
| download | sharkey-fb91ab4080ade2234d6ea21cd877d635d226b6c3.tar.gz sharkey-fb91ab4080ade2234d6ea21cd877d635d226b6c3.tar.bz2 sharkey-fb91ab4080ade2234d6ea21cd877d635d226b6c3.zip | |
Merge branch 'develop' into notification-visibility-read-2
Diffstat (limited to 'src/client/scripts/paging.ts')
| -rw-r--r-- | src/client/scripts/paging.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/client/scripts/paging.ts b/src/client/scripts/paging.ts index 048c797753..1f302753e1 100644 --- a/src/client/scripts/paging.ts +++ b/src/client/scripts/paging.ts @@ -15,6 +15,14 @@ export default (opts) => ({ more: false, backed: false, isBackTop: false, + ilObserver: new IntersectionObserver( + (entries) => entries.some((entry) => entry.isIntersecting) + && !this.moreFetching + && !this.fetching + && this.fetchMore() + ), + loadMoreElement: null as Element, + unsubscribeInfiniteScrollMutation: null as any, }; }, @@ -51,6 +59,29 @@ export default (opts) => ({ }); }, + mounted() { + this.$nextTick(() => { + if (this.$refs.loadMore) { + this.loadMoreElement = this.$refs.loadMore instanceof Element ? this.$refs.loadMore : this.$refs.loadMore.$el; + if (this.$store.state.device.enableInfiniteScroll) this.ilObserver.observe(this.loadMoreElement); + this.loadMoreElement.addEventListener('click', this.fetchMore); + + this.unsubscribeInfiniteScrollMutation = this.$store.subscribe(mutation => { + if (mutation.type !== 'device/setInfiniteScrollEnabling') return; + + if (mutation.payload) return this.ilObserver.observe(this.loadMoreElement); + return this.ilObserver.unobserve(this.loadMoreElement); + }); + } + }); + }, + + beforeDestroy() { + this.ilObserver.disconnect(); + if (this.$refs.loadMore) this.loadMoreElement.removeEventListener('click', this.fetchMore); + if (this.unsubscribeInfiniteScrollMutation) this.unsubscribeInfiniteScrollMutation(); + }, + methods: { updateItem(i, item) { Vue.set((this as any).items, i, item); |