summaryrefslogtreecommitdiff
path: root/src/client/scripts
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2020-05-31 12:53:06 +0900
committerGitHub <noreply@github.com>2020-05-31 12:53:06 +0900
commita1e0c866aafec521b6aca1e8bb3099c82ba925f5 (patch)
treeabf1cb2c1c9370731a836936ef7495490fb0205b /src/client/scripts
parentResolve #6412 (#6416) (diff)
downloadsharkey-a1e0c866aafec521b6aca1e8bb3099c82ba925f5.tar.gz
sharkey-a1e0c866aafec521b6aca1e8bb3099c82ba925f5.tar.bz2
sharkey-a1e0c866aafec521b6aca1e8bb3099c82ba925f5.zip
feat(client): 自動でもっと見るオプション (#6403)
* wip * ugokanai * wip * implement setting subscribing * fix lint * :v: * Update notifications.vue Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'src/client/scripts')
-rw-r--r--src/client/scripts/paging.ts31
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);