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:
Guillermo 2024-04-02 09:04:52 -06:00 committed by GitHub
parent 7cc19b50fc
commit 28e8e539f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 43 deletions

View file

@ -1,13 +1,8 @@
<script lang="ts">
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
import {
NotificationType,
notificationController,
} from '$lib/components/shared-components/notification/notification';
import type { OnStack } from '$lib/utils/actions';
import { handleError } from '$lib/utils/handle-error';
import { updateAssets } from '@immich/sdk';
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
import type { OnStack } from '$lib/utils/actions';
import { stackAssets } from '$lib/utils/asset-utils';
import { mdiImageMultipleOutline } from '@mdi/js';
export let onStack: OnStack | undefined;
@ -15,44 +10,10 @@
const { clearSelect, getOwnedAssets } = getAssetControlContext();
const handleStack = async () => {
try {
const assets = [...getOwnedAssets()];
const parent = assets.at(0);
if (parent == undefined) {
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 ?? 0;
for (const asset of children) {
asset.stackParentId = parent?.id;
// Add grand-children's count to new parent
childrenCount += asset.stackCount == undefined ? 1 : asset.stackCount + 1;
// Reset children stack info
asset.stackCount = null;
asset.stack = [];
}
parent.stackCount = childrenCount;
await stackAssets([...getOwnedAssets()], (ids) => {
onStack?.(ids);
notificationController.show({
message: `Stacked ${ids.length + 1} assets`,
type: NotificationType.Info,
timeout: 1500,
});
clearSelect();
} catch (error) {
handleError(error, `Unable to stack`);
}
});
};
</script>