mirror of
https://github.com/immich-app/immich.git
synced 2025-07-01 21:40:10 +02:00
feat(web): add keyboard shortcut to stack selected photos (#5983)
* feat(web): add keyboard shortcut to stack selected photos * refactor(web): deduplicate logic to stack assets * Fix linting errors * fix(web): incorrect count of stacked photos * chore: cleanup --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
parent
7cc19b50fc
commit
28e8e539f6
4 changed files with 53 additions and 43 deletions
web/src/lib/utils
|
@ -11,6 +11,7 @@ import {
|
|||
createAlbum,
|
||||
defaults,
|
||||
getDownloadInfo,
|
||||
updateAssets,
|
||||
type AssetResponseDto,
|
||||
type AssetTypeEnum,
|
||||
type DownloadInfoDto,
|
||||
|
@ -270,6 +271,44 @@ export const getSelectedAssets = (assets: Set<AssetResponseDto>, user: UserRespo
|
|||
return ids;
|
||||
};
|
||||
|
||||
export async function stackAssets(assets: Array<AssetResponseDto>, onStack: (ds: string[]) => void) {
|
||||
try {
|
||||
const parent = assets.at(0);
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
const children = assets.slice(1);
|
||||
const ids = children.map(({ id }) => id);
|
||||
|
||||
if (children.length > 0) {
|
||||
await updateAssets({ assetBulkUpdateDto: { ids, stackParentId: parent.id } });
|
||||
}
|
||||
|
||||
let childrenCount = parent.stackCount || 1;
|
||||
for (const asset of children) {
|
||||
asset.stackParentId = parent.id;
|
||||
// Add grand-children's count to new parent
|
||||
childrenCount += asset.stackCount || 1;
|
||||
// Reset children stack info
|
||||
asset.stackCount = null;
|
||||
asset.stack = [];
|
||||
}
|
||||
|
||||
parent.stackCount = childrenCount;
|
||||
|
||||
notificationController.show({
|
||||
message: `Stacked ${ids.length + 1} assets`,
|
||||
type: NotificationType.Info,
|
||||
timeout: 1500,
|
||||
});
|
||||
|
||||
onStack(ids);
|
||||
} catch (error) {
|
||||
handleError(error, `Unable to stack`);
|
||||
}
|
||||
}
|
||||
|
||||
export const selectAllAssets = async (assetStore: AssetStore, assetInteractionStore: AssetInteractionStore) => {
|
||||
if (get(isSelectingAllAssets)) {
|
||||
// Selection is already ongoing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue