1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-16 00:36:47 +01:00

feat(web): restore scroll position on navigating back to search page (#12042)

* feat(web): restore scroll position on navigating back to search page

* set 0 for scroll X

* lint

* simplify
This commit is contained in:
Alex 2024-08-26 11:26:23 -05:00 committed by GitHub
parent 3ac42edc74
commit edf47dbbd0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,6 +40,7 @@
import AlbumCardGroup from '$lib/components/album-page/album-card-group.svelte';
import { isAlbumsRoute, isPeopleRoute } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { afterUpdate, tick } from 'svelte';
const MAX_ASSET_COUNT = 5000;
let { isViewing: showAssetViewer } = assetViewingStore;
@ -54,6 +55,8 @@
let searchResultAlbums: AlbumResponseDto[] = [];
let searchResultAssets: AssetResponseDto[] = [];
let isLoading = true;
let scrollY = 0;
let scrollYHistory = 0;
const onEscape = () => {
if ($showAssetViewer) {
@ -70,6 +73,13 @@
$preventRaceConditionSearchBar = false;
};
// save and restore scroll position
afterUpdate(() => {
if (scrollY) {
scrollYHistory = scrollY;
}
});
afterNavigate(({ from }) => {
// Prevent setting previousRoute to the current page.
if (from?.url && from.route.id !== $page.route.id) {
@ -84,6 +94,14 @@
if (isAlbumsRoute(route)) {
previousRoute = AppRoute.EXPLORE;
}
tick()
.then(() => {
window.scrollTo(0, scrollYHistory);
})
.catch(() => {
// do nothing
});
});
let selectedAssets: Set<AssetResponseDto> = new Set();
@ -203,7 +221,7 @@
}
</script>
<svelte:window use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: onEscape }} />
<svelte:window use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: onEscape }} bind:scrollY />
<section>
{#if isMultiSelectionMode}