mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05: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 AlbumCardGroup from '$lib/components/album-page/album-card-group.svelte';
|
||||||
import { isAlbumsRoute, isPeopleRoute } from '$lib/utils/navigation';
|
import { isAlbumsRoute, isPeopleRoute } from '$lib/utils/navigation';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
import { afterUpdate, tick } from 'svelte';
|
||||||
|
|
||||||
const MAX_ASSET_COUNT = 5000;
|
const MAX_ASSET_COUNT = 5000;
|
||||||
let { isViewing: showAssetViewer } = assetViewingStore;
|
let { isViewing: showAssetViewer } = assetViewingStore;
|
||||||
|
@ -54,6 +55,8 @@
|
||||||
let searchResultAlbums: AlbumResponseDto[] = [];
|
let searchResultAlbums: AlbumResponseDto[] = [];
|
||||||
let searchResultAssets: AssetResponseDto[] = [];
|
let searchResultAssets: AssetResponseDto[] = [];
|
||||||
let isLoading = true;
|
let isLoading = true;
|
||||||
|
let scrollY = 0;
|
||||||
|
let scrollYHistory = 0;
|
||||||
|
|
||||||
const onEscape = () => {
|
const onEscape = () => {
|
||||||
if ($showAssetViewer) {
|
if ($showAssetViewer) {
|
||||||
|
@ -70,6 +73,13 @@
|
||||||
$preventRaceConditionSearchBar = false;
|
$preventRaceConditionSearchBar = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// save and restore scroll position
|
||||||
|
afterUpdate(() => {
|
||||||
|
if (scrollY) {
|
||||||
|
scrollYHistory = scrollY;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
afterNavigate(({ from }) => {
|
afterNavigate(({ from }) => {
|
||||||
// Prevent setting previousRoute to the current page.
|
// Prevent setting previousRoute to the current page.
|
||||||
if (from?.url && from.route.id !== $page.route.id) {
|
if (from?.url && from.route.id !== $page.route.id) {
|
||||||
|
@ -84,6 +94,14 @@
|
||||||
if (isAlbumsRoute(route)) {
|
if (isAlbumsRoute(route)) {
|
||||||
previousRoute = AppRoute.EXPLORE;
|
previousRoute = AppRoute.EXPLORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tick()
|
||||||
|
.then(() => {
|
||||||
|
window.scrollTo(0, scrollYHistory);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
// do nothing
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let selectedAssets: Set<AssetResponseDto> = new Set();
|
let selectedAssets: Set<AssetResponseDto> = new Set();
|
||||||
|
@ -203,7 +221,7 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: onEscape }} />
|
<svelte:window use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: onEscape }} bind:scrollY />
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
{#if isMultiSelectionMode}
|
{#if isMultiSelectionMode}
|
||||||
|
|
Loading…
Add table
Reference in a new issue