mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(web): un-stack from the photos page ; fix stack count (#8419)
* feat(web): un-stack from the photos page ; fix stack count * move stuff outside of try-catch block * small optim
This commit is contained in:
parent
a3feca2580
commit
c227f9893e
6 changed files with 129 additions and 60 deletions
|
|
@ -12,7 +12,7 @@
|
|||
import { stackAssetsStore } from '$lib/stores/stacked-asset.store';
|
||||
import { user } from '$lib/stores/user.store';
|
||||
import { getAssetJobMessage, getSharedLink, handlePromiseError, isSharedLink } from '$lib/utils';
|
||||
import { addAssetsToAlbum, addAssetsToNewAlbum, downloadFile } from '$lib/utils/asset-utils';
|
||||
import { addAssetsToAlbum, addAssetsToNewAlbum, downloadFile, unstackAssets } from '$lib/utils/asset-utils';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { shortcuts } from '$lib/utils/shortcut';
|
||||
import { SlideshowHistory } from '$lib/utils/slideshow-history';
|
||||
|
|
@ -28,7 +28,6 @@
|
|||
getAllAlbums,
|
||||
runAssetJobs,
|
||||
updateAsset,
|
||||
updateAssets,
|
||||
updateAlbumInfo,
|
||||
type ActivityResponseDto,
|
||||
type AlbumResponseDto,
|
||||
|
|
@ -481,20 +480,15 @@
|
|||
};
|
||||
|
||||
const handleUnstack = async () => {
|
||||
try {
|
||||
const ids = $stackAssetsStore.map(({ id }) => id);
|
||||
await updateAssets({ assetBulkUpdateDto: { ids, removeParent: true } });
|
||||
for (const child of $stackAssetsStore) {
|
||||
child.stackParentId = null;
|
||||
child.stackCount = 0;
|
||||
child.stack = [];
|
||||
dispatch('action', { type: AssetAction.ADD, asset: child });
|
||||
const unstackedAssets = await unstackAssets($stackAssetsStore);
|
||||
if (unstackedAssets) {
|
||||
for (const asset of unstackedAssets) {
|
||||
dispatch('action', {
|
||||
type: AssetAction.ADD,
|
||||
asset,
|
||||
});
|
||||
}
|
||||
|
||||
dispatch('close');
|
||||
notificationController.show({ type: NotificationType.Info, message: 'Un-stacked', timeout: 1500 });
|
||||
} catch (error) {
|
||||
handleError(error, `Unable to unstack`);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,45 @@
|
|||
<script lang="ts">
|
||||
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
|
||||
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';
|
||||
import { getAssetControlContext } from '$lib/components/photos-page/asset-select-control-bar.svelte';
|
||||
import { mdiImageMinusOutline, mdiImageMultipleOutline } from '@mdi/js';
|
||||
import { stackAssets, unstackAssets } from '$lib/utils/asset-utils';
|
||||
import type { OnStack, OnUnstack } from '$lib/utils/actions';
|
||||
|
||||
export let unstack = false;
|
||||
export let onStack: OnStack | undefined;
|
||||
export let onUnstack: OnUnstack | undefined;
|
||||
|
||||
const { clearSelect, getOwnedAssets } = getAssetControlContext();
|
||||
|
||||
const handleStack = async () => {
|
||||
await stackAssets([...getOwnedAssets()], (ids) => {
|
||||
const selectedAssets = [...getOwnedAssets()];
|
||||
const ids = await stackAssets(selectedAssets);
|
||||
if (ids) {
|
||||
onStack?.(ids);
|
||||
clearSelect();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleUnstack = async () => {
|
||||
const selectedAssets = [...getOwnedAssets()];
|
||||
if (selectedAssets.length !== 1) {
|
||||
return;
|
||||
}
|
||||
const { stack } = selectedAssets[0];
|
||||
if (!stack) {
|
||||
return;
|
||||
}
|
||||
const assets = [selectedAssets[0], ...stack];
|
||||
const unstackedAssets = await unstackAssets(assets);
|
||||
if (unstackedAssets) {
|
||||
onUnstack?.(unstackedAssets);
|
||||
}
|
||||
clearSelect();
|
||||
};
|
||||
</script>
|
||||
|
||||
<MenuOption text="Stack" icon={mdiImageMultipleOutline} on:click={handleStack} />
|
||||
{#if unstack}
|
||||
<MenuOption text="Un-stack" icon={mdiImageMinusOutline} on:click={handleUnstack} />
|
||||
{:else}
|
||||
<MenuOption text="Stack" icon={mdiImageMultipleOutline} on:click={handleStack} />
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -89,11 +89,10 @@
|
|||
};
|
||||
|
||||
const onStackAssets = async () => {
|
||||
if ($selectedAssets.size > 1) {
|
||||
await stackAssets(Array.from($selectedAssets), (ids) => {
|
||||
assetStore.removeAssets(ids);
|
||||
dispatch('escape');
|
||||
});
|
||||
const ids = await stackAssets(Array.from($selectedAssets));
|
||||
if (ids) {
|
||||
assetStore.removeAssets(ids);
|
||||
dispatch('escape');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue