mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
fix(web): viewing asset lock (#19499)
* fix(web): viewing asset lock * fix: lint * make mutex stateless --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
73733370a2
commit
fb384fe90b
4 changed files with 20 additions and 1 deletions
|
|
@ -91,7 +91,7 @@
|
|||
empty,
|
||||
}: Props = $props();
|
||||
|
||||
let { isViewing: showAssetViewer, asset: viewingAsset, preloadAssets, gridScrollTarget } = assetViewingStore;
|
||||
let { isViewing: showAssetViewer, asset: viewingAsset, preloadAssets, gridScrollTarget, mutex } = assetViewingStore;
|
||||
|
||||
let element: HTMLElement | undefined = $state();
|
||||
|
||||
|
|
@ -438,6 +438,7 @@
|
|||
};
|
||||
|
||||
const handlePrevious = async () => {
|
||||
const release = await mutex.acquire();
|
||||
const laterAsset = await timelineManager.getLaterAsset($viewingAsset);
|
||||
|
||||
if (laterAsset) {
|
||||
|
|
@ -447,11 +448,14 @@
|
|||
await navigate({ targetRoute: 'current', assetId: laterAsset.id });
|
||||
}
|
||||
|
||||
release();
|
||||
return !!laterAsset;
|
||||
};
|
||||
|
||||
const handleNext = async () => {
|
||||
const release = await mutex.acquire();
|
||||
const earlierAsset = await timelineManager.getEarlierAsset($viewingAsset);
|
||||
|
||||
if (earlierAsset) {
|
||||
const preloadAsset = await timelineManager.getEarlierAsset(earlierAsset);
|
||||
const asset = await getAssetInfo({ id: earlierAsset.id, key: authManager.key });
|
||||
|
|
@ -459,6 +463,7 @@
|
|||
await navigate({ targetRoute: 'current', assetId: earlierAsset.id });
|
||||
}
|
||||
|
||||
release();
|
||||
return !!earlierAsset;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ import { authManager } from '$lib/managers/auth-manager.svelte';
|
|||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||
import { type AssetGridRouteSearchParams } from '$lib/utils/navigation';
|
||||
import { getAssetInfo, type AssetResponseDto } from '@immich/sdk';
|
||||
import { Mutex } from 'async-mutex';
|
||||
import { readonly, writable } from 'svelte/store';
|
||||
|
||||
function createAssetViewingStore() {
|
||||
const viewingAssetStoreState = writable<AssetResponseDto>();
|
||||
const preloadAssets = writable<TimelineAsset[]>([]);
|
||||
const viewState = writable<boolean>(false);
|
||||
const viewingAssetMutex = new Mutex();
|
||||
const gridScrollTarget = writable<AssetGridRouteSearchParams | null | undefined>();
|
||||
|
||||
const setAsset = (asset: AssetResponseDto, assetsToPreload: TimelineAsset[] = []) => {
|
||||
|
|
@ -28,6 +30,7 @@ function createAssetViewingStore() {
|
|||
|
||||
return {
|
||||
asset: readonly(viewingAssetStoreState),
|
||||
mutex: viewingAssetMutex,
|
||||
preloadAssets: readonly(preloadAssets),
|
||||
isViewing: viewState,
|
||||
gridScrollTarget,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue