feat(client): 自動でもっと見るオプション (#6403)

* wip

* ugokanai

* wip

* implement setting subscribing

* fix lint

* ✌️

* Update notifications.vue

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
tamaina
2020-05-31 12:53:06 +09:00
committed by GitHub
parent eda7d60c26
commit a1e0c866aa
11 changed files with 96 additions and 17 deletions

View File

@ -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);