fix scroll position resetting on admin panel
All checks were successful
delpoy / build-and-deploy (push) Successful in 1m2s

This commit is contained in:
bytedream 2024-12-28 02:20:37 +01:00
parent 5935b0d561
commit 8ea1750f1a

View File

@ -6,6 +6,21 @@
let bodyElem: HTMLTableSectionElement;
let intersectionElem: HTMLElement;
async function onUpdateProxy() {
let scrollElem: HTMLElement | null = bodyElem;
while (scrollElem && scrollElem.scrollHeight <= scrollElem.clientHeight) {
scrollElem = scrollElem.parentElement;
}
const scrollTop = scrollElem?.scrollTop ?? 0;
await onUpdate();
if (scrollElem) scrollElem.scrollTop = scrollTop;
await tick();
}
async function getIntersectionElement(): Promise<HTMLElement> {
if (!bodyElem.lastElementChild) {
await new Promise<void>((resolve) => {
@ -21,8 +36,7 @@
}
onMount(async () => {
await onUpdate();
await tick();
await onUpdateProxy();
if (!bodyElem) return;
@ -33,8 +47,7 @@
const rows = bodyElem.rows.length;
await onUpdate();
await tick();
await onUpdateProxy();
if (rows === bodyElem.rows.length) return;
observer.observe((intersectionElem = await getIntersectionElement()));