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

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

View File

@ -6,6 +6,20 @@
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();
await tick();
if (scrollElem) scrollElem.scrollTop = scrollTop;
}
async function getIntersectionElement(): Promise<HTMLElement> {
if (!bodyElem.lastElementChild) {
await new Promise<void>((resolve) => {
@ -21,8 +35,7 @@
}
onMount(async () => {
await onUpdate();
await tick();
await onUpdateProxy();
if (!bodyElem) return;
@ -33,8 +46,7 @@
const rows = bodyElem.rows.length;
await onUpdate();
await tick();
await onUpdateProxy();
if (rows === bodyElem.rows.length) return;
observer.observe((intersectionElem = await getIntersectionElement()));