diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 3c7dc6640..38827ea35 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -509,6 +509,7 @@ addedRelays: "追加済みのリレー" serviceworkerInfo: "プッシュ通知を行うには有効する必要があります。" deletedNote: "削除された投稿" invisibleNote: "非公開の投稿" +enableInfiniteScroll: "自動でもっと見る" _theme: explore: "テーマを探す" diff --git a/src/client/components/drive.vue b/src/client/components/drive.vue index 65eb1cb81..3e7b7d04a 100644 --- a/src/client/components/drive.vue +++ b/src/client/components/drive.vue @@ -19,17 +19,17 @@ @drop.prevent.stop="onDrop" >
-
+
- {{ $t('loadMore') }} + {{ $t('loadMore') }}
-
+
- {{ $t('loadMore') }} + {{ $t('loadMore') }}

{{ $t('empty-draghover') }}

@@ -116,6 +116,13 @@ export default Vue.extend({ fetching: true, + ilFilesObserver: new IntersectionObserver( + (entries) => entries.some((entry) => entry.isIntersecting) + && !this.fetching && this.moreFiles && + this.fetchMoreFiles() + ), + moreFilesElement: null as Element, + faAngleRight }; }, @@ -127,6 +134,12 @@ export default Vue.extend({ }, mounted() { + if (this.$store.state.device.enableInfiniteScroll && this.$refs.loadMoreFiles) { + this.$nextTick(() => { + this.ilFilesObserver.observe((this.$refs.loadMoreFiles as Vue).$el) + }); + } + this.connection = this.$root.stream.useSharedConnection('drive'); this.connection.on('fileCreated', this.onStreamDriveFileCreated); @@ -143,8 +156,17 @@ export default Vue.extend({ } }, + activated() { + if (this.$store.state.device.enableInfiniteScroll) { + this.$nextTick(() => { + this.ilFilesObserver.observe((this.$refs.loadMoreFiles as Vue).$el) + }); + } + }, + beforeDestroy() { this.connection.dispose(); + this.ilFilesObserver.disconnect(); }, methods: { diff --git a/src/client/components/notes.vue b/src/client/components/notes.vue index 515bc58e2..c83cbd1aa 100644 --- a/src/client/components/notes.vue +++ b/src/client/components/notes.vue @@ -7,8 +7,8 @@ -
- @@ -18,8 +18,8 @@ -
- diff --git a/src/client/components/notifications.vue b/src/client/components/notifications.vue index 3ed198a04..36464a309 100644 --- a/src/client/components/notifications.vue +++ b/src/client/components/notifications.vue @@ -5,7 +5,7 @@ - diff --git a/src/client/components/ui/pagination.vue b/src/client/components/ui/pagination.vue index e888b7420..79d322bbc 100644 --- a/src/client/components/ui/pagination.vue +++ b/src/client/components/ui/pagination.vue @@ -4,8 +4,8 @@
-
- +
+ diff --git a/src/client/components/user-list.vue b/src/client/components/user-list.vue index 7a9cd58a4..0204cf9d0 100644 --- a/src/client/components/user-list.vue +++ b/src/client/components/user-list.vue @@ -22,7 +22,7 @@
-
diff --git a/src/client/components/users-dialog.vue b/src/client/components/users-dialog.vue index 0e0cc36c2..575d03118 100644 --- a/src/client/components/users-dialog.vue +++ b/src/client/components/users-dialog.vue @@ -15,8 +15,7 @@
- - diff --git a/src/client/pages/messaging/messaging-room.vue b/src/client/pages/messaging/messaging-room.vue index e97d5532a..a95305cab 100644 --- a/src/client/pages/messaging/messaging-room.vue +++ b/src/client/pages/messaging/messaging-room.vue @@ -16,7 +16,7 @@

{{ $t('noMessagesYet') }}

{{ $t('noMoreHistory') }}

- @@ -40,7 +40,6 @@ import { faArrowCircleDown, faFlag, faUsers, faInfoCircle } from '@fortawesome/f import XList from '../../components/date-separated-list.vue'; import XMessage from './messaging-room.message.vue'; import XForm from './messaging-room.form.vue'; -import { url } from '../../config'; import parseAcct from '../../../misc/acct/parse'; export default Vue.extend({ @@ -61,6 +60,13 @@ export default Vue.extend({ connection: null, showIndicator: false, timer: null, + ilObserver: new IntersectionObserver( + (entries) => entries.some((entry) => entry.isIntersecting) + && !this.fetching + && !this.fetchingMoreMessages + && this.existMoreMessages + && this.fetchMoreMessages() + ), faArrowCircleDown, faFlag, faUsers, faInfoCircle }; }, @@ -77,6 +83,9 @@ export default Vue.extend({ mounted() { this.fetch(); + if (this.$store.state.device.enableInfiniteScroll) { + this.$nextTick(() => this.ilObserver.observe(this.$refs.loadMore as Element)); + } }, beforeDestroy() { @@ -85,6 +94,8 @@ export default Vue.extend({ window.removeEventListener('scroll', this.onScroll); document.removeEventListener('visibilitychange', this.onVisibilitychange); + + this.ilObserver.disconnect(); }, methods: { @@ -112,8 +123,12 @@ export default Vue.extend({ document.addEventListener('visibilitychange', this.onVisibilitychange); this.fetchMessages().then(() => { - this.fetching = false; this.scrollToBottom(); + + // もっと見るの交差検知を発火させないためにfetchは + // スクロールが終わるまでfalseにしておく + // scrollendのようなイベントはないのでsetTimeoutで + setTimeout(() => this.fetching = false, 300); }); }, diff --git a/src/client/pages/preferences/index.vue b/src/client/pages/preferences/index.vue index 14d22bf02..148b4a97b 100644 --- a/src/client/pages/preferences/index.vue +++ b/src/client/pages/preferences/index.vue @@ -67,6 +67,7 @@ {{ $t('showFixedPostForm') }} + {{ $t('enableInfiniteScroll') }} {{ $t('disablePagesScript') }}
@@ -182,6 +183,11 @@ export default Vue.extend({ set(value) { this.$store.commit('device/set', { key: 'showFixedPostForm', value }); } }, + enableInfiniteScroll: { + get() { return this.$store.state.device.enableInfiniteScroll; }, + set(value) { this.$store.commit('device/setInfiniteScrollEnabling', value); } + }, + sfxVolume: { get() { return this.$store.state.device.sfxVolume; }, set(value) { this.$store.commit('device/set', { key: 'sfxVolume', value: parseFloat(value, 10) }); } diff --git a/src/client/scripts/paging.ts b/src/client/scripts/paging.ts index 048c79775..1f302753e 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); diff --git a/src/client/store.ts b/src/client/store.ts index c1d7d3991..3eb221b5c 100644 --- a/src/client/store.ts +++ b/src/client/store.ts @@ -56,6 +56,7 @@ export const defaultDeviceSettings = { imageNewTab: false, showFixedPostForm: false, disablePagesScript: true, + enableInfiniteScroll: true, roomGraphicsQuality: 'medium', roomUseOrthographicCamera: true, sfxVolume: 0.3, @@ -333,6 +334,10 @@ export default () => new Vuex.Store({ setUserData(state, x: { userId: string; data: any }) { state.userData[x.userId] = copy(x.data); }, + + setInfiniteScrollEnabling(state, x: boolean) { + state.enableInfiniteScroll = x; + }, } },