lint & revert conflicting navigateAssetRoute change

This commit is contained in:
Calum Dingwall 2024-07-31 22:52:37 -04:00
parent b630e4fb4a
commit 1574f60f07
3 changed files with 15 additions and 11 deletions

View File

@ -66,7 +66,7 @@ async function navigateAssetRoute(route: AssetRoute) {
const { assetId } = route; const { assetId } = route;
const next = assetId ? currentUrlReplaceAssetId(assetId) : currentUrlWithoutAsset(); const next = assetId ? currentUrlReplaceAssetId(assetId) : currentUrlWithoutAsset();
if (next !== currentUrl()) { if (next !== currentUrl()) {
await goto(next, { replaceState: false, noScroll: true }); await goto(next, { replaceState: false });
} }
} }

View File

@ -26,11 +26,12 @@
}); });
onMount(() => { onMount(() => {
let newScroll = sessionStorage.getItem(SessionStorageKey.SCROLL_POSITION); let newScroll = sessionStorage.getItem(SessionStorageKey.SCROLL_POSITION);
if (newScroll) if (newScroll) {
scrollSlot.scroll({ scrollSlot.scroll({
top: parseFloat(newScroll), top: Number.parseFloat(newScroll),
behavior: 'instant', behavior: 'instant',
}); });
}
sessionStorage.removeItem(SessionStorageKey.SCROLL_POSITION); sessionStorage.removeItem(SessionStorageKey.SCROLL_POSITION);
}); });

View File

@ -65,7 +65,9 @@
beforeNavigate(({ to }) => { beforeNavigate(({ to }) => {
// Save current scroll information when going into a person page. // Save current scroll information when going into a person page.
if (to && to.url.pathname.startsWith(AppRoute.PEOPLE)) { if (to && to.url.pathname.startsWith(AppRoute.PEOPLE)) {
if (nextPage) sessionStorage.setItem(SessionStorageKey.INFINITE_SCROLL_PAGE, nextPage.toString()); if (nextPage) {
sessionStorage.setItem(SessionStorageKey.INFINITE_SCROLL_PAGE, nextPage.toString());
}
sessionStorage.setItem(SessionStorageKey.SCROLL_POSITION, scrollSlot.scrollTop.toString()); sessionStorage.setItem(SessionStorageKey.SCROLL_POSITION, scrollSlot.scrollTop.toString());
} else { } else {
sessionStorage.removeItem(SessionStorageKey.INFINITE_SCROLL_PAGE); sessionStorage.removeItem(SessionStorageKey.INFINITE_SCROLL_PAGE);
@ -75,11 +77,12 @@
const restoreScrollPosition = () => { const restoreScrollPosition = () => {
let newScroll = sessionStorage.getItem(SessionStorageKey.SCROLL_POSITION); let newScroll = sessionStorage.getItem(SessionStorageKey.SCROLL_POSITION);
if (newScroll) if (newScroll) {
scrollSlot.scroll({ scrollSlot.scroll({
top: parseFloat(newScroll), top: Number.parseFloat(newScroll),
behavior: 'instant', behavior: 'instant',
}); });
}
sessionStorage.removeItem(SessionStorageKey.SCROLL_POSITION); sessionStorage.removeItem(SessionStorageKey.SCROLL_POSITION);
}; };
@ -94,19 +97,19 @@
let newNextPage = sessionStorage.getItem(SessionStorageKey.INFINITE_SCROLL_PAGE); let newNextPage = sessionStorage.getItem(SessionStorageKey.INFINITE_SCROLL_PAGE);
if (newNextPage && nextPage) { if (newNextPage && nextPage) {
let startingPage = nextPage, let startingPage = nextPage,
pagesToLoad = parseInt(newNextPage) - nextPage; pagesToLoad = Number.parseInt(newNextPage) - nextPage;
if (pagesToLoad) { if (pagesToLoad) {
handlePromiseError( handlePromiseError(
Promise.all( Promise.all(
Array(pagesToLoad).map((_, i) => { Array.from({ length: pagesToLoad }).map((_, i) => {
return getAllPeople({ withHidden: true, page: startingPage + i }); return getAllPeople({ withHidden: true, page: startingPage + i });
}), }),
).then((pages) => { ).then((pages) => {
pages.forEach((page) => { for (const page of pages) {
people = people.concat(page.people); people = people.concat(page.people);
}); }
nextPage = pages[pages.length - 1].hasNextPage ? startingPage + pagesToLoad : null; nextPage = pages.at(-1)?.hasNextPage ? startingPage + pagesToLoad : null;
restoreScrollPosition(); // wait until extra pages are loaded restoreScrollPosition(); // wait until extra pages are loaded
}), }),
); );