mirror of
https://github.com/immich-app/immich.git
synced 2025-02-11 01:18:24 -05:00
fix(web): ensure current asset index stays within bounds (#14013)
This commit is contained in:
parent
35f24270fe
commit
d3fe238eef
1 changed files with 23 additions and 8 deletions
|
@ -66,11 +66,15 @@
|
||||||
|
|
||||||
const handleNext = async () => {
|
const handleNext = async () => {
|
||||||
try {
|
try {
|
||||||
const asset = onNext ? await onNext() : assets[++currentViewAssetIndex];
|
let asset: AssetResponseDto | undefined;
|
||||||
if (asset) {
|
if (onNext) {
|
||||||
setAsset(asset);
|
asset = await onNext();
|
||||||
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
} else {
|
||||||
|
currentViewAssetIndex = Math.min(currentViewAssetIndex + 1, assets.length - 1);
|
||||||
|
asset = assets[currentViewAssetIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await navigateToAsset(asset);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, $t('errors.cannot_navigate_next_asset'));
|
handleError(error, $t('errors.cannot_navigate_next_asset'));
|
||||||
}
|
}
|
||||||
|
@ -78,16 +82,27 @@
|
||||||
|
|
||||||
const handlePrevious = async () => {
|
const handlePrevious = async () => {
|
||||||
try {
|
try {
|
||||||
const asset = onPrevious ? await onPrevious() : assets[--currentViewAssetIndex];
|
let asset: AssetResponseDto | undefined;
|
||||||
if (asset) {
|
if (onPrevious) {
|
||||||
setAsset(asset);
|
asset = await onPrevious();
|
||||||
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
} else {
|
||||||
|
currentViewAssetIndex = Math.max(currentViewAssetIndex - 1, 0);
|
||||||
|
asset = assets[currentViewAssetIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await navigateToAsset(asset);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, $t('errors.cannot_navigate_previous_asset'));
|
handleError(error, $t('errors.cannot_navigate_previous_asset'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const navigateToAsset = async (asset?: AssetResponseDto) => {
|
||||||
|
if (asset && asset.id !== $viewingAsset.id) {
|
||||||
|
setAsset(asset);
|
||||||
|
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleAction = async (action: Action) => {
|
const handleAction = async (action: Action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case AssetAction.ARCHIVE:
|
case AssetAction.ARCHIVE:
|
||||||
|
|
Loading…
Add table
Reference in a new issue