Update MkTimeline.vue

This commit is contained in:
syuilo 2025-05-02 15:42:28 +09:00
parent dcaf020afb
commit ef82d103ff
1 changed files with 32 additions and 7 deletions

View File

@ -56,7 +56,7 @@ SPDX-License-Identifier: AGPL-3.0-only
import { computed, watch, onUnmounted, provide, useTemplateRef, TransitionGroup, onMounted, shallowRef, ref } from 'vue'; import { computed, watch, onUnmounted, provide, useTemplateRef, TransitionGroup, onMounted, shallowRef, ref } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { useInterval } from '@@/js/use-interval.js'; import { useInterval } from '@@/js/use-interval.js';
import { isHeadVisible, scrollToTop } from '@@/js/scroll.js'; import { getScrollContainer, scrollToTop } from '@@/js/scroll.js';
import type { BasicTimelineType } from '@/timelines.js'; import type { BasicTimelineType } from '@/timelines.js';
import type { PagingCtx } from '@/use/use-pagination.js'; import type { PagingCtx } from '@/use/use-pagination.js';
import { usePagination } from '@/use/use-pagination.js'; import { usePagination } from '@/use/use-pagination.js';
@ -98,7 +98,35 @@ provide('inTimeline', true);
provide('tl_withSensitive', computed(() => props.withSensitive)); provide('tl_withSensitive', computed(() => props.withSensitive));
provide('inChannel', computed(() => props.src === 'channel')); provide('inChannel', computed(() => props.src === 'channel'));
function isTop() {
if (scrollContainer == null) return false;
if (rootEl.value == null) return false;
const scrollTop = scrollContainer.scrollTop;
const tlTop = rootEl.value.offsetTop - scrollContainer.offsetTop;
return scrollTop <= tlTop;
}
let scrollContainer: HTMLElement | null = null;
function onScrollContainerScroll() {
if (isTop()) {
paginator.releaseQueue();
}
}
const rootEl = useTemplateRef('rootEl'); const rootEl = useTemplateRef('rootEl');
watch(rootEl, (el) => {
if (el && scrollContainer == null) {
scrollContainer = getScrollContainer(el)!;
scrollContainer.addEventListener('scroll', onScrollContainerScroll, { passive: true }); // scrollendios
}
}, { immediate: true });
onUnmounted(() => {
if (scrollContainer) {
scrollContainer.removeEventListener('scroll', onScrollContainerScroll);
}
});
type TimelineQueryType = { type TimelineQueryType = {
antennaId?: string, antennaId?: string,
@ -122,9 +150,8 @@ const POLLING_INTERVAL =
if (!store.s.realtimeMode) { if (!store.s.realtimeMode) {
useInterval(async () => { useInterval(async () => {
const isTop = rootEl.value == null ? false : isHeadVisible(rootEl.value, 16);
paginator.fetchNewer({ paginator.fetchNewer({
toQueue: !isTop, toQueue: !isTop(),
}); });
}, POLLING_INTERVAL, { }, POLLING_INTERVAL, {
immediate: false, immediate: false,
@ -133,9 +160,8 @@ if (!store.s.realtimeMode) {
} }
globalEvents.on('notePosted', (note: Misskey.entities.Note) => { globalEvents.on('notePosted', (note: Misskey.entities.Note) => {
const isTop = rootEl.value == null ? false : isHeadVisible(rootEl.value, 16);
paginator.fetchNewer({ paginator.fetchNewer({
toQueue: !isTop, toQueue: !isTop(),
}); });
}); });
@ -151,8 +177,7 @@ function prepend(note: Misskey.entities.Note) {
note._shouldInsertAd_ = true; note._shouldInsertAd_ = true;
} }
const isTop = isHeadVisible(rootEl.value, 16); if (isTop()) {
if (isTop) {
paginator.prepend(note); paginator.prepend(note);
} else { } else {
paginator.enqueue(note); paginator.enqueue(note);