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:
parent
3ac42edc74
commit
edf47dbbd0
1 changed files with 19 additions and 1 deletions
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue