Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): 連合一覧等のページネーションが壊れていたのを修正 #14439

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fix: 設定変更時のリロード確認ダイアログが複数個表示されることがある問題を修正
- Fix: ファイルの詳細ページのファイルの説明で改行が正しく表示されない問題を修正
(Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/commit/bde6bb0bd2e8b0d027e724d2acdb8ae0585a8110)
- Fix: 一部画面のページネーションが動作しにくくなっていたのを修正 ( #12766 , #11449 )

### Server
- Feat: Misskey® Reactions Buffering Technology™ (RBT)により、リアクションの作成負荷を低減することが可能に
Expand Down
19 changes: 14 additions & 5 deletions packages/frontend-shared/js/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,27 @@ export function getScrollPosition(el: HTMLElement | null): number {
return container == null ? window.scrollY : container.scrollTop;
}

export function onScrollTop(el: HTMLElement, cb: () => unknown, tolerance = 1, once = false) {
export function onScrollTop(el: HTMLElement, cb: (topVisible: boolean) => unknown, tolerance = 1, once = false) {
// とりあえず評価してみる
if (el.isConnected && isTopVisible(el)) {
cb();
const firstTopVisible = isTopVisible(el);
if (el.isConnected && firstTopVisible) {
cb(firstTopVisible);
if (once) return null;
}

const container = getScrollContainer(el) ?? window;

// 以下のケースにおいて、cbが何度も呼び出されてしまって具合が悪いので1回呼んだら以降は無視するようにする
// - スクロールイベントは1回のスクロールで複数回発生することがある
// - toleranceの範囲内に収まる程度の微量なスクロールが発生した
let prevTopVisible = firstTopVisible;
const onScroll = () => {
if (!document.body.contains(el)) return;
if (isTopVisible(el, tolerance)) {
cb();

const topVisible = isTopVisible(el, tolerance);
if (topVisible !== prevTopVisible) {
prevTopVisible = topVisible;
cb(topVisible);
if (once) removeListener();
}
};
Expand Down Expand Up @@ -126,6 +134,7 @@ export function scrollToBottom(

export function isTopVisible(el: HTMLElement, tolerance = 1): boolean {
const scrollTop = getScrollPosition(el);
if (_DEV_) console.log(scrollTop, tolerance, scrollTop <= tolerance);
return scrollTop <= tolerance;
}

Expand Down
13 changes: 5 additions & 8 deletions packages/frontend/src/components/MkPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ const items = ref<MisskeyEntityMap>(new Map());
*/
const queue = ref<MisskeyEntityMap>(new Map());

const offset = ref(0);

/**
* 初期化中かどうか(trueならMkLoadingで全て隠す)
*/
Expand Down Expand Up @@ -179,7 +177,9 @@ watch([backed, contentEl], () => {
if (!backed.value) {
if (!contentEl.value) return;

scrollRemove.value = (props.pagination.reversed ? onScrollBottom : onScrollTop)(contentEl.value, executeQueue, TOLERANCE);
scrollRemove.value = props.pagination.reversed
? onScrollBottom(contentEl.value, executeQueue, TOLERANCE)
: onScrollTop(contentEl.value, (topVisible) => { if (topVisible) executeQueue(); }, TOLERANCE);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上から下に向かってスクロールするときは発動させず、下から上に向かってスクロールしたときに発動するようにしています。

} else {
if (scrollRemove.value) scrollRemove.value();
scrollRemove.value = null;
Expand Down Expand Up @@ -223,7 +223,6 @@ async function init(): Promise<void> {
more.value = true;
}

offset.value = res.length;
error.value = false;
fetching.value = false;
}, err => {
Expand All @@ -244,7 +243,7 @@ const fetchMore = async (): Promise<void> => {
...params,
limit: SECOND_FETCH_LIMIT,
...(props.pagination.offsetMode ? {
offset: offset.value,
offset: items.value.size,
} : {
untilId: Array.from(items.value.keys()).at(-1),
}),
Expand Down Expand Up @@ -294,7 +293,6 @@ const fetchMore = async (): Promise<void> => {
moreFetching.value = false;
}
}
offset.value += res.length;
}, err => {
moreFetching.value = false;
});
Expand All @@ -308,7 +306,7 @@ const fetchMoreAhead = async (): Promise<void> => {
...params,
limit: SECOND_FETCH_LIMIT,
...(props.pagination.offsetMode ? {
offset: offset.value,
offset: items.value.size,
} : {
sinceId: Array.from(items.value.keys()).at(-1),
}),
Expand All @@ -320,7 +318,6 @@ const fetchMoreAhead = async (): Promise<void> => {
items.value = concatMapWithArray(items.value, res);
more.value = true;
}
offset.value += res.length;
moreFetching.value = false;
}, err => {
moreFetching.value = false;
Expand Down
Loading