From 04b6a3a3ba64d424ff4628a5600cf8c48242ef1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EC=A7=80=ED=99=98=20=28Cooper=29?= Date: Sun, 17 Sep 2023 15:06:16 +0900 Subject: [PATCH] Restore `infinite-scroll` broken on new dashboard (#6918) --- source/features/infinite-scroll.tsx | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/features/infinite-scroll.tsx b/source/features/infinite-scroll.tsx index 4098f61efb44..f5df3ea98d91 100644 --- a/source/features/infinite-scroll.tsx +++ b/source/features/infinite-scroll.tsx @@ -7,35 +7,28 @@ import features from '../feature-manager.js'; import observe from '../helpers/selector-observer.js'; import onAbort from '../helpers/abort-controller.js'; -const loadMore = debounce(() => { - const button = select('[role="tabpanel"]:not([hidden]) button.ajax-pagination-btn')!; +const loadMore = debounce((button: HTMLButtonElement) => { button.click(); - button.textContent = 'Loading…'; // If GH hasn't loaded the JS, the click will not load anything. // We can detect if it worked by looking at the button's state, // and then trying again (auto-debounced) if (!button.disabled) { - loadMore(); + loadMore(button); } }, {wait: 200}); -const inView = new IntersectionObserver(([{isIntersecting}]) => { +const inView = new IntersectionObserver(([{target, isIntersecting}]) => { if (isIntersecting) { - loadMore(); + loadMore(target as HTMLButtonElement); } }, { rootMargin: '500px', // https://github.com/refined-github/refined-github/pull/505#issuecomment-309273098 }); -function init(signal: AbortSignal): void { - onAbort(signal, inView); - observe('.ajax-pagination-btn', button => { - inView.observe(button); - }, {signal}); - +function copyFooter(originalFooter: HTMLElement): void { // Copy the footer links to the sidebar to make them more accessible. Also keep a copy in the footer. - const footer = select('.footer > .d-flex')!.cloneNode(true); + const footer = originalFooter.cloneNode(true); for (const child of footer.children) { child.classList.remove('pl-lg-4', 'col-xl-3'); @@ -48,12 +41,19 @@ function init(signal: AbortSignal): void { ); } +function init(signal: AbortSignal): void { + onAbort(signal, inView); + observe('.ajax-pagination-btn', button => { + inView.observe(button); + }, {signal}); + + observe('.footer > .d-flex', copyFooter, {signal}); +} + void features.add(import.meta.url, { include: [ pageDetect.isDashboard, ], - deduplicate: 'has-rgh', - awaitDomReady: true, // Must wait for the whole page to load anyway init, });