mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
fix(web): previous/next asset navigation (#3107)
* fix(web): previous/next asset navigation * Apply suggestions from code review Co-authored-by: Thomas <9749173+uhthomas@users.noreply.github.com> * Call setViewingAsset once * Make code more readable * Avoid recursive call * Simplify return statement * Set position of the bucket to Unknown --------- Co-authored-by: Thomas <9749173+uhthomas@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
814030be77
commit
37edef834e
3 changed files with 71 additions and 20 deletions
|
|
@ -30,6 +30,15 @@ function createAssetStore() {
|
|||
return height;
|
||||
};
|
||||
|
||||
const refreshLoadedAssets = (state: AssetGridState): void => {
|
||||
state.loadedAssets = {};
|
||||
state.buckets.forEach((bucket, bucketIndex) =>
|
||||
bucket.assets.map((asset) => {
|
||||
state.loadedAssets[asset.id] = bucketIndex;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set initial state
|
||||
* @param viewportHeight
|
||||
|
|
@ -54,6 +63,7 @@ function createAssetStore() {
|
|||
position: BucketPosition.Unknown,
|
||||
})),
|
||||
assets: [],
|
||||
loadedAssets: {},
|
||||
userId,
|
||||
});
|
||||
|
||||
|
|
@ -101,6 +111,7 @@ function createAssetStore() {
|
|||
state.buckets[bucketIndex].assets = assets;
|
||||
state.buckets[bucketIndex].position = position;
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
refreshLoadedAssets(state);
|
||||
return state;
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
@ -123,6 +134,7 @@ function createAssetStore() {
|
|||
_removeBucket(state.buckets[bucketIndex].bucketDate);
|
||||
}
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
refreshLoadedAssets(state);
|
||||
return state;
|
||||
});
|
||||
};
|
||||
|
|
@ -132,6 +144,7 @@ function createAssetStore() {
|
|||
const bucketIndex = state.buckets.findIndex((b) => b.bucketDate === bucketDate);
|
||||
state.buckets.splice(bucketIndex, 1);
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
refreshLoadedAssets(state);
|
||||
return state;
|
||||
});
|
||||
};
|
||||
|
|
@ -180,6 +193,7 @@ function createAssetStore() {
|
|||
state.buckets[bucketIndex].assets[assetIndex].isFavorite = isFavorite;
|
||||
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
refreshLoadedAssets(state);
|
||||
return state;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue